Skip to content

Commit e72fef1

Browse files
committed
Remove global nulls_last settings. It's defined by class now.
1 parent 244f0dd commit e72fef1

File tree

11 files changed

+55
-37
lines changed

11 files changed

+55
-37
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88
* Add support of Ruby 3.0
99
* Switch from Travis to Github Actions
1010
* Improve specs
11-
* `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364))
1211
* Fix lib loading with JRuby (fixes [#371](https://github.com/jbox-web/ajax-datatables-rails/issues/371))
1312
* Raise an error when column's `cond:` setting is unknown
1413
* Make global search and column search work together (merge: [#350](https://github.com/jbox-web/ajax-datatables-rails/pull/350), fixes: [#258](https://github.com/jbox-web/ajax-datatables-rails/issues/258))
1514

15+
* `AjaxDatatablesRails.config` is removed with no replacement. The gem is now configless :)
16+
* `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364))
17+
* `AjaxDatatablesRails.config.nulls_last=` is removed and is configured per datatable class now (or by column). It defaults to false.
18+
19+
To mitigate this 3 changes see the [migration doc](/doc/migrate.md).
20+
1621
## 1.2.0 (2020-04-19)
1722

1823
* Drop support of Rails 4.x

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,15 @@ end
170170
* `:null_value` for nil field
171171
* `Proc` for whatever (see [here](https://github.com/jbox-web/ajax-datatables-rails-sample-project/blob/master/app/datatables/city_datatable.rb) for real example)
172172

173-
The `nulls_last` param allows for nulls to be ordered last.
173+
The `nulls_last` param allows for nulls to be ordered last. You can configure it by column, like above, or by datatable class :
174+
175+
```ruby
176+
class MyDatatable < AjaxDatatablesRails::ActiveRecord
177+
self.nulls_last = true
178+
179+
# ... other methods (view_columns, data...)
180+
end
181+
```
174182

175183
See [here](#columns-syntax) to get more details about columns definitions and how to play with associated models.
176184

ajax-datatables-rails.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
2323

2424
s.files = `git ls-files`.split("\n")
2525

26-
s.add_runtime_dependency 'railties', '>= 5.1'
2726
s.add_runtime_dependency 'zeitwerk'
2827

2928
s.add_development_dependency 'activerecord-oracle_enhanced-adapter'

doc/migrate.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
## To migrate from `v1.0.x` to `v1.3.0`
2+
3+
The *v1.3.0* version has some breaking changes :
4+
5+
* `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364))
6+
7+
This change is transparent for everyone. Just remove `AjaxDatatablesRails.config.db_adapter=` from your configuration (if exists) and it should work fine.
8+
9+
Now you can use AjaxDatatablesRails in multi-db environments.
10+
11+
* `AjaxDatatablesRails.config.nulls_last=` is removed and is configured per datatable class now (or by column). It defaults to false.
12+
13+
This change is easy to mitigate : add `self.nulls_last = true` in [`ApplicationDatatable`](https://github.com/jbox-web/ajax-datatables-rails#create-a-master-parent-class-easy) and remove `AjaxDatatablesRails.config.nulls_last=`
14+
15+
```ruby
16+
class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord
17+
self.nulls_last = true
18+
# puts commonly used methods here
19+
end
20+
```
21+
22+
* `AjaxDatatablesRails.config` is removed with no replacement
23+
24+
Fix the two changes above and remove any configuration file about AjaxDatatablesRails. The gem is now configless :)
25+
126
## To migrate from `v0.4.x` to `v1.0.0`
227

328
The *v1.0.0* version is a **major break** from *v0.4*.

lib/ajax-datatables-rails.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'active_support/configurable'
4-
53
require 'zeitwerk'
64
loader = Zeitwerk::Loader.for_gem
75
generators = "#{__dir__}/generators"
@@ -13,18 +11,4 @@
1311
loader.setup
1412

1513
module AjaxDatatablesRails
16-
# Configure AjaxDatatablesRails global settings
17-
#
18-
# AjaxDatatablesRails.configure do |config|
19-
# config.nulls_last = true
20-
# end
21-
22-
def self.configure
23-
yield @config ||= AjaxDatatablesRails::Configuration.new
24-
end
25-
26-
# AjaxDatatablesRails global settings
27-
def self.config
28-
@config ||= AjaxDatatablesRails::Configuration.new
29-
end
3014
end

lib/ajax-datatables-rails/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module AjaxDatatablesRails
44
class Base
55

66
class_attribute :db_adapter, default: ActiveRecord::Base.connection.adapter_name.downcase.to_sym
7+
class_attribute :nulls_last, default: false
78

89
attr_reader :params, :options, :datatable
910

lib/ajax-datatables-rails/configuration.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def db_adapter
7777
@datatable.db_adapter
7878
end
7979

80+
def nulls_last
81+
@datatable.nulls_last
82+
end
83+
8084
end
8185
end
8286
end

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ class SimpleOrder
99
DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC].freeze
1010

1111
def initialize(datatable, options = {})
12-
@datatable = datatable
13-
@options = options
14-
@adapter = datatable.db_adapter
12+
@datatable = datatable
13+
@options = options
14+
@adapter = datatable.db_adapter
15+
@nulls_last = datatable.nulls_last
1516
end
1617

1718
def query(sort_column)
@@ -37,7 +38,7 @@ def column_direction
3738
end
3839

3940
def sort_nulls_last?
40-
column.nulls_last? || AjaxDatatablesRails.config.nulls_last == true
41+
column.nulls_last? || @nulls_last == true
4142
end
4243

4344
def nulls_last_sql

spec/ajax-datatables-rails/datatable/simple_order_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
end
1515

1616
describe 'option methods with nulls last' do
17-
describe 'using global option' do
18-
before { AjaxDatatablesRails.config.nulls_last = true }
19-
after { AjaxDatatablesRails.config.nulls_last = false }
17+
describe 'using class option' do
18+
before { parent.nulls_last = true }
19+
after { parent.nulls_last = false }
2020

2121
it 'sql query' do
2222
skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced'

0 commit comments

Comments
 (0)