grid_table 1.4 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e0f68c331f3af5023c4259e67dd20e1a54e5679
4
- data.tar.gz: 2cf32700cc72c621f88e8d0fb94f76094c638021
3
+ metadata.gz: d6037e9f180243d42182c4eb6a5739fc457d256d
4
+ data.tar.gz: 34ddfabfae33383f69c46f4f4d1920d78d1ab495
5
5
  SHA512:
6
- metadata.gz: a164408606bd8da871a3e434b5896bad3aba26cb666df8e19a22ef0215b6ee1dc40c7f892083f55f87805f4b6940192e87c5dd9a3b8dff849c1f57700ac87fca
7
- data.tar.gz: 12f2edc524f24d218b0ec301a1d59de22853c7a87c146156491b2c593547433573fea095507d05cc49c6c581f7588cd22bd5352e92cac2afeb3c68acc4a07523
6
+ metadata.gz: 9b74ed307fb917880bad85c2f519f962c6370cc9fdf1f9515a1b0ba4ed828a1f37f28ed65fd8f525d3d7ff21753796bf91c13e41c8250f0482c1d6560b469e5f
7
+ data.tar.gz: 83537aac94772bf820c8650a246eccc7171c51eecac5215b91b1b4053e36db27b455faf288f32b2d0b09913853194fa3ef82b21c64321186dae180aaeb54b1f5
@@ -34,27 +34,27 @@ class GridTable::Control
34
34
  false
35
35
  end
36
36
 
37
- attr_writer :model, :attribute, :source, :source_class, :source_column, :source_alias, :filter, :polymorphic
37
+ attr_writer :model, :attribute, :source, :source_class, :source_column, :source_sql, :filter, :polymorphic
38
38
 
39
39
  def filter(param_filter_value, records)
40
- return if @filter.nil?
40
+ return records if @filter == false
41
41
 
42
42
  arel_query = nil
43
43
  strategy_map = {
44
- exact_match: ->(col) { col.eq(param_filter_value) },
45
- prefix: ->(col) { col.matches("#{param_filter_value}%") },
46
- suffix: ->(col) { col.matches("%#{param_filter_value}") },
47
- fuzzy: ->(col) { col.matches("%#{param_filter_value}%") },
48
- array: ->(_col) { "#{column} @> ARRAY[#{[param_filter_value].flatten.join(',')}]" },
49
- date_range: ->(_col) { "#{source_table.name}.#{column} BETWEEN #{param_filter_value}" }
44
+ exact_match: ->(col) { "(#{col}) = #{param_filter_value}" },
45
+ prefix: ->(col) { "(#{col}) ILIKE '#{param_filter_value}%'" },
46
+ suffix: ->(col) { "(#{col}) ILIKE '%#{param_filter_value}'" },
47
+ fuzzy: ->(col) { "(#{col}) ILIKE '%#{param_filter_value}%'" },
48
+ array: ->(col) { "(#{col}) @> ARRAY[#{[param_filter_value].flatten.join(',')}]" },
49
+ date_range: ->(_col) { "(#{col}) BETWEEN #{param_filter_value}" }
50
50
  }
51
51
 
52
52
  polymorphic_models.each_with_index do |klass, i|
53
53
  # TODO: implement array filtering
54
- arel_query = i.zero? ? strategy_map[strategy].call(klass.arel_table[column]) : arel_query.or(strategy_map[strategy].call(klass.arel_table[column]))
54
+ arel_query = i.zero? ? strategy_map[strategy].call(polymorphic_table_with_column(klass)) : arel_query.or(strategy_map[strategy].call(polymorphic_table_with_column(klass)))
55
55
  end
56
56
 
57
- arel_query ||= strategy_map[strategy].call(source_table[column])
57
+ arel_query ||= strategy_map[strategy].call(table_with_column)
58
58
  prepared_records(records).where(arel_query)
59
59
  end
60
60
 
@@ -113,7 +113,11 @@ class GridTable::Control
113
113
  end
114
114
 
115
115
  def table_with_column
116
- @source_alias || "#{source_table.name}.#{column}"
116
+ @source_sql || "#{source_table.name}.#{column}"
117
+ end
118
+
119
+ def polymorphic_table_with_column(klass)
120
+ @source_sql || "#{klass.arel_table.name}.#{klass.arel_table[column].name}"
117
121
  end
118
122
 
119
123
  def model_fk
@@ -12,7 +12,7 @@ class GridTable::Table
12
12
  source: options[:source],
13
13
  source_class: options[:source_class],
14
14
  source_column: options[:source_column],
15
- source_alias: options[:source_alias],
15
+ source_sql: options[:source_sql],
16
16
  filter: options[:filter],
17
17
  polymorphic: options[:polymorphic]
18
18
  )
@@ -1,3 +1,3 @@
1
1
  module GridTable
2
- VERSION = '1.4'.freeze
2
+ VERSION = '1.4.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grid_table
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.4'
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Principe