Skip to content

Commit 76e1f6a

Browse files
committed
Merge branch 'master' of github.com:jbox-web/ajax-datatables-rails into order_nulls_last_new
2 parents 3d9dc6e + 5fd462b commit 76e1f6a

File tree

12 files changed

+98
-35
lines changed

12 files changed

+98
-35
lines changed

.rubocop.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ Layout/EmptyLinesAroundModuleBody:
2626
Layout/EmptyLineBetweenDefs:
2727
Enabled: false
2828

29+
Metrics/CyclomaticComplexity:
30+
Max: 7
31+
2932
Metrics/LineLength:
3033
Enabled: false
3134

3235
Metrics/BlockLength:
3336
Max: 30
3437

38+
Metrics/MethodLength:
39+
Max: 15
40+
3541
Metrics/ClassLength:
3642
Max: 130
3743

.travis.yml

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,52 @@ language: ruby
33
sudo: required
44
cache: bundler
55
rvm:
6-
- 2.2.9
7-
- 2.3.6
6+
- 2.2.10
7+
- 2.3.7
88
gemfile:
99
- gemfiles/rails_4.0.13.gemfile
1010
- gemfiles/rails_4.1.16.gemfile
1111
- gemfiles/rails_4.2.10.gemfile
12-
- gemfiles/rails_5.0.6.gemfile
13-
- gemfiles/rails_5.1.5.gemfile
12+
- gemfiles/rails_5.0.7.gemfile
13+
- gemfiles/rails_5.1.6.gemfile
14+
- gemfiles/rails_5.2.0.gemfile
1415
matrix:
1516
include:
16-
- rvm: 2.4.3
17+
- rvm: 2.4.4
1718
gemfile: gemfiles/rails_4.2.10.gemfile
1819
env: DB_ADAPTER=postgresql
19-
- rvm: 2.4.3
20-
gemfile: gemfiles/rails_5.0.6.gemfile
20+
- rvm: 2.4.4
21+
gemfile: gemfiles/rails_5.0.7.gemfile
2122
env: DB_ADAPTER=postgresql
22-
- rvm: 2.4.3
23-
gemfile: gemfiles/rails_5.1.5.gemfile
23+
- rvm: 2.4.4
24+
gemfile: gemfiles/rails_5.1.6.gemfile
2425
env: DB_ADAPTER=postgresql
25-
- rvm: 2.4.3
26+
- rvm: 2.4.4
27+
gemfile: gemfiles/rails_5.2.0.gemfile
28+
env: DB_ADAPTER=postgresql
29+
- rvm: 2.4.4
2630
gemfile: gemfiles/rails_4.2.10.gemfile
2731
env: DB_ADAPTER=mysql2
28-
- rvm: 2.4.3
29-
gemfile: gemfiles/rails_5.0.6.gemfile
32+
- rvm: 2.4.4
33+
gemfile: gemfiles/rails_5.0.7.gemfile
34+
env: DB_ADAPTER=mysql2
35+
- rvm: 2.4.4
36+
gemfile: gemfiles/rails_5.1.6.gemfile
3037
env: DB_ADAPTER=mysql2
31-
- rvm: 2.4.3
32-
gemfile: gemfiles/rails_5.1.5.gemfile
38+
- rvm: 2.4.4
39+
gemfile: gemfiles/rails_5.2.0.gemfile
3340
env: DB_ADAPTER=mysql2
34-
- rvm: 2.4.3
41+
- rvm: 2.4.4
3542
gemfile: gemfiles/rails_4.2.10.gemfile
3643
env: DB_ADAPTER=oracle_enhanced
37-
- rvm: 2.4.3
38-
gemfile: gemfiles/rails_5.0.6.gemfile
44+
- rvm: 2.4.4
45+
gemfile: gemfiles/rails_5.0.7.gemfile
46+
env: DB_ADAPTER=oracle_enhanced
47+
- rvm: 2.4.4
48+
gemfile: gemfiles/rails_5.1.6.gemfile
3949
env: DB_ADAPTER=oracle_enhanced
40-
- rvm: 2.4.3
41-
gemfile: gemfiles/rails_5.1.5.gemfile
50+
- rvm: 2.4.4
51+
gemfile: gemfiles/rails_5.2.0.gemfile
4252
env: DB_ADAPTER=oracle_enhanced
4353
after_success:
4454
- bundle exec codeclimate-test-reporter
@@ -53,6 +63,8 @@ addons:
5363
- mysql-client-core-5.6
5464
- mysql-client-5.6
5565
before_install:
66+
- gem update --system
67+
- gem install bundler
5668
- sh -c "if [ '$DB_ADAPTER' = 'mysql2' ]; then mysql -e 'create database ajax_datatables_rails;'; fi"
5769
- sh -c "if [ '$DB_ADAPTER' = 'postgresql' ]; then psql -c 'create database ajax_datatables_rails;' -U postgres; fi"
5870
- sh -c "if [ '$DB_ADAPTER' = 'oracle_enhanced' ]; then ./spec/install_oracle.sh; fi"

Appraisals

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ RAILS_VERSIONS = {
1212
'4.2.10' => {
1313
'activerecord-oracle_enhanced-adapter' => '~> 1.6.0'
1414
},
15-
'5.0.6' => {
15+
'5.0.7' => {
1616
'activerecord-oracle_enhanced-adapter' => '~> 1.7.0',
1717
'ruby-oci8' => ''
1818
},
19-
'5.1.5' => {
19+
'5.1.6' => {
2020
'activerecord-oracle_enhanced-adapter' => '~> 1.8.0',
2121
'ruby-oci8' => ''
22+
},
23+
'5.2.0' => {
24+
'activerecord-oracle_enhanced-adapter' => '~> 5.2.0',
25+
'ruby-oci8' => ''
2226
}
2327
}.freeze
2428

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Fix: "orderable" option has no effect [Issue #245](https://github.com/jbox-web/ajax-datatables-rails/issues/245)
88
* Change: Rename `additional_datas` method as `additional_data` [PR #251](https://github.com/jbox-web/ajax-datatables-rails/pull/251)
99
* Change: Added timezone support for daterange [PR #261](https://github.com/jbox-web/ajax-datatables-rails/pull/261)
10+
* Various improvements in internal API
1011

1112
**Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x
1213

README.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
> This gem is targeted at Datatables version 1.10.x.
1414
>
1515
> It's tested against :
16-
> * Rails 4.0.13 / 4.1.16 / 4.2.10 / 5.0.6 / 5.1.5
17-
> * Ruby 2.2.8 / 2.3.5 / 2.4.2
18-
> * Postgresql
19-
> * MySQL
16+
> * Rails 4.0.13 / 4.1.16 / 4.2.10 / 5.0.7 / 5.1.6 / 5.2.0
17+
> * Ruby 2.2.10 / 2.3.7 / 2.4.4 / 2.5.1
18+
> * Postgresql 9.6
19+
> * MySQL 5.6
2020
> * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle))
2121
2222
## Description
@@ -573,7 +573,7 @@ class MyCustomDatatable < AjaxDatatablesRails::Base
573573
{
574574
id: check_box_tag('users[]', record.id),
575575
first_name: link_to(record.fname, edit_resource_path(record)),
576-
email: mail_to(record.email)
576+
email: mail_to(record.email),
577577
# other attributes
578578
}
579579
end
@@ -583,20 +583,46 @@ end
583583

584584
If you want to keep things tidy in the data mapping method, you could use
585585
[Draper](https://github.com/drapergem/draper) to define column mappings like below.
586+
On the long term it's much more cleaner than using `def_delegator` since decorators are reusable so we strongly recommand you to
587+
use Draper decorators. It will help you to keep your DataTables class small and clean and keep focused on what they should do (mostly) : filtering records ;)
588+
The presentation layer should rely on Decorators class.
589+
590+
Example :
586591

587592
```ruby
588593
...
589594
def data
590595
records.map do |record|
591596
{
592-
id: record.decorate.id,
593-
first_name: record.decorate.first_name,
594-
email: record.decorate.email
597+
id: record.decorate.id,
598+
first_name: record.decorate.link_to,
599+
email: record.decorate.email,
595600
# other attributes
601+
dt_actions: record.decorate.dt_actions,
602+
DT_RowId: record.id,
596603
}
597604
end
598605
end
599606
...
607+
608+
class UserDecorator < ApplicationDecorator
609+
delegate :id, :first_name
610+
611+
def link_to
612+
h.link_to first_name, h.user_path(object)
613+
end
614+
615+
def email
616+
h.mail_to object.email
617+
end
618+
619+
def dt_actions
620+
links = []
621+
links << h.link_to 'Edit', h.edit_user_path(object) if h.policy(object).update?
622+
links << h.link_to 'Delete', h.user_path(object), method: :delete, remote: true if h.policy(object).destroy?
623+
h.safe_join(links, '')
624+
end
625+
end
600626
```
601627

602628

gemfiles/rails_4.2.10.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
source "https://rubygems.org"
44

55
gem "rails", "4.2.10"
6+
gem "mysql2", "0.4.10"
67
gem "activerecord-oracle_enhanced-adapter", "~> 1.6.0"
78
gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced"
89

gemfiles/rails_5.0.6.gemfile renamed to gemfiles/rails_5.0.7.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source "https://rubygems.org"
44

5-
gem "rails", "5.0.6"
5+
gem "rails", "5.0.7"
66
gem "activerecord-oracle_enhanced-adapter", "~> 1.7.0"
77
gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced"
88

gemfiles/rails_5.1.5.gemfile renamed to gemfiles/rails_5.1.6.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source "https://rubygems.org"
44

5-
gem "rails", "5.1.5"
5+
gem "rails", "5.1.6"
66
gem "activerecord-oracle_enhanced-adapter", "~> 1.8.0"
77
gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced"
88

gemfiles/rails_5.2.0.gemfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "rails", "5.2.0"
6+
gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0"
7+
gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced"
8+
9+
group :test do
10+
gem "codeclimate-test-reporter", "~> 1.0.0"
11+
end
12+
13+
gemspec path: "../"

lib/ajax-datatables-rails/datatable/column.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ class Column
1818

1919
include Search
2020
include Order
21+
prepend DateFilter unless AjaxDatatablesRails.old_rails?
2122

22-
unless AjaxDatatablesRails.old_rails?
23-
prepend DateFilter
24-
end
2523

2624
def initialize(datatable, index, options)
2725
@datatable = datatable

0 commit comments

Comments
 (0)