File tree Expand file tree Collapse file tree 5 files changed +23
-14
lines changed
lib/ajax-datatables-rails/datatable Expand file tree Collapse file tree 5 files changed +23
-14
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,18 @@ module AjaxDatatablesRails
44 module Datatable
55 class Column
66
7+ TYPE_CAST_DEFAULT = 'VARCHAR'
8+ TYPE_CAST_MYSQL = 'CHAR'
9+ TYPE_CAST_SQLITE = 'TEXT'
10+ TYPE_CAST_ORACLE = 'VARCHAR2(4000)'
11+
712 DB_ADAPTER_TYPE_CAST = {
8- mysql : 'CHAR' ,
9- mysql2 : 'CHAR' ,
10- sqlite : 'TEXT' ,
11- sqlite3 : 'TEXT' ,
12- oracle : 'VARCHAR2(4000)' ,
13- oracleenhanced : 'VARCHAR2(4000)'
13+ mysql : TYPE_CAST_MYSQL ,
14+ mysql2 : TYPE_CAST_MYSQL ,
15+ sqlite : TYPE_CAST_SQLITE ,
16+ sqlite3 : TYPE_CAST_SQLITE ,
17+ oracle : TYPE_CAST_ORACLE ,
18+ oracleenhanced : TYPE_CAST_ORACLE
1419 } . freeze
1520
1621 attr_reader :datatable , :index , :options
@@ -65,7 +70,7 @@ def formatted_value
6570 private
6671
6772 def type_cast
68- @type_cast ||= ( DB_ADAPTER_TYPE_CAST [ AjaxDatatablesRails . config . db_adapter ] || 'VARCHAR' )
73+ @type_cast ||= DB_ADAPTER_TYPE_CAST . fetch ( AjaxDatatablesRails . config . db_adapter , TYPE_CAST_DEFAULT )
6974 end
7075
7176 def casted_column
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ class Column
66 module Search
77
88 SMALLEST_PQ_INTEGER = -2147483648
9- LARGEST_PQ_INTEGER = 2147483647
9+ LARGEST_PQ_INTEGER = 2147483647
10+ NOT_NULL_VALUE = '!NULL'
11+ EMPTY_VALUE = ''
1012
1113 def searchable?
1214 @view_column . fetch ( :searchable , true )
@@ -74,7 +76,7 @@ def non_regex_search
7476 end
7577
7678 def null_value_search
77- if formatted_value == '!NULL'
79+ if formatted_value == NOT_NULL_VALUE
7880 table [ field ] . not_eq ( nil )
7981 else
8082 table [ field ] . eq ( nil )
@@ -90,7 +92,7 @@ def raw_search(cond)
9092 end
9193
9294 def empty_search
93- casted_column . matches ( '' )
95+ casted_column . matches ( EMPTY_VALUE )
9496 end
9597
9698 def is_searchable_integer?
Original file line number Diff line number Diff line change 33module AjaxDatatablesRails
44 module Datatable
55
6- TRUE_VALUE = 'true'
7-
86 class Datatable
97 attr_reader :datatable , :options
108
Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ module AjaxDatatablesRails
44 module Datatable
55 class SimpleOrder
66
7- DIRECTIONS = %w[ DESC ASC ] . freeze
7+ DIRECTION_ASC = 'ASC'
8+ DIRECTION_DESC = 'DESC'
9+ DIRECTIONS = [ DIRECTION_ASC , DIRECTION_DESC ] . freeze
810
911 def initialize ( datatable , options = { } )
1012 @datatable = datatable
@@ -24,7 +26,7 @@ def column
2426 end
2527
2628 def direction
27- DIRECTIONS . find { |dir | dir == column_direction } || 'ASC'
29+ DIRECTIONS . find { |dir | dir == column_direction } || DIRECTION_ASC
2830 end
2931
3032 private
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ module AjaxDatatablesRails
44 module Datatable
55 class SimpleSearch
66
7+ TRUE_VALUE = 'true'
8+
79 def initialize ( options = { } )
810 @options = options
911 end
You can’t perform that action at this time.
0 commit comments