Skip to content

Commit 7faacef

Browse files
committed
Replace case/when by a hash lookup
1 parent cdf2e6d commit 7faacef

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,29 @@ def sort_nulls_last?
4141
column.nulls_last? || @nulls_last == true
4242
end
4343

44+
PG_NULL_STYLE = 'NULLS LAST'
45+
MYSQL_NULL_STYLE = 'IS NULL'
46+
private_constant :PG_NULL_STYLE
47+
private_constant :MYSQL_NULL_STYLE
48+
49+
NULL_STYLE_MAP = {
50+
pg: PG_NULL_STYLE,
51+
postgresql: PG_NULL_STYLE,
52+
postgres: PG_NULL_STYLE,
53+
postgis: PG_NULL_STYLE,
54+
oracle: PG_NULL_STYLE,
55+
mysql: MYSQL_NULL_STYLE,
56+
mysql2: MYSQL_NULL_STYLE,
57+
trilogy: MYSQL_NULL_STYLE,
58+
sqlite: MYSQL_NULL_STYLE,
59+
sqlite3: MYSQL_NULL_STYLE,
60+
}.freeze
61+
private_constant :NULL_STYLE_MAP
62+
4463
def nulls_last_sql
4564
return unless sort_nulls_last?
4665

47-
case @adapter
48-
when :pg, :postgresql, :postgres, :oracle, :postgis
49-
'NULLS LAST'
50-
when :mysql, :mysql2, :trilogy, :sqlite, :sqlite3
51-
'IS NULL'
52-
else
53-
raise "unsupported database adapter: #{@adapter}"
54-
end
66+
NULL_STYLE_MAP[@adapter] || raise("unsupported database adapter: #{@adapter}")
5567
end
5668

5769
end

0 commit comments

Comments
 (0)