Skip to content

Commit 93f753f

Browse files
committed
Improve encapsulation
1 parent 888388d commit 93f753f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module AjaxDatatablesRails
44
module Datatable
55

66
class Datatable
7-
attr_reader :datatable, :options
7+
attr_reader :options
88

99
def initialize(datatable)
1010
@datatable = datatable
@@ -41,7 +41,7 @@ def search
4141

4242
def columns
4343
@columns ||= get_param(:columns).map do |index, column_options|
44-
Column.new(datatable, index, column_options)
44+
Column.new(@datatable, index, column_options)
4545
end
4646
end
4747

@@ -73,6 +73,10 @@ def get_param(param)
7373
options[param].to_unsafe_h.with_indifferent_access
7474
end
7575

76+
def db_adapter
77+
@datatable.db_adapter
78+
end
79+
7680
end
7781
end
7882
end

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class SimpleOrder
1111
def initialize(datatable, options = {})
1212
@datatable = datatable
1313
@options = options
14+
@adapter = datatable.db_adapter
1415
end
1516

1617
def query(sort_column)
@@ -42,15 +43,13 @@ def sort_nulls_last?
4243
def nulls_last_sql
4344
return unless sort_nulls_last?
4445

45-
adapter = @datatable.datatable.db_adapter
46-
47-
case adapter
46+
case @adapter
4847
when :pg, :postgresql, :postgres, :oracle
4948
'NULLS LAST'
5049
when :mysql, :mysql2, :sqlite, :sqlite3
5150
'IS NULL'
5251
else
53-
raise "unsupported database adapter: #{adapter}"
52+
raise "unsupported database adapter: #{@adapter}"
5453
end
5554
end
5655

0 commit comments

Comments
 (0)