activerecord-filter 5.0.0.7 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/active_record/filter.rb +53 -33
- data/lib/active_record/filter/version.rb +1 -1
- metadata +19 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a535b323a4ffbf5fc7628089b0c25e8f5034c82d15002938ec5b13081a9ba13a
|
4
|
+
data.tar.gz: 8429eb3399716797f4b969e2205b5e47b1989abd6f65e55e0f2c4405860fb6ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dfdd6e75dc5c276f8394a82bb7750e4c4db093c7d1744b4d1cff418a4606d31bb9530ea4c1e896703e6fe651d3923c3094e42a19cc6c98d181df99165b88dbe
|
7
|
+
data.tar.gz: 0ae3202e02a5b2e79be030189a1b73bc0fdfcb09b35574f36c05a0059834316ca5ac864d79941a4c7b228eefe5e0d9ccc65347f525286f1b19aaf226cc201688
|
data/lib/active_record/filter.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'arel/extensions'
|
3
|
-
require 'action_controller/metal/strong_parameters'
|
4
3
|
|
5
4
|
class ActiveRecord::UnkownFilterError < NoMethodError
|
6
5
|
end
|
@@ -58,14 +57,15 @@ module ActiveRecord
|
|
58
57
|
elsif value != true && value != false && value != 'true' && value != 'false' && !value.nil?
|
59
58
|
relations << key
|
60
59
|
end
|
61
|
-
elsif key.to_s.ends_with?('_ids') && reflection = klass._reflections[key.to_s.gsub(/_ids$/, 's')]
|
60
|
+
elsif !klass.columns_hash.has_key?(key.to_s) && key.to_s.ends_with?('_ids') && reflection = klass._reflections[key.to_s.gsub(/_ids$/, 's')]
|
62
61
|
relations << reflection.name
|
63
62
|
elsif reflection = klass.reflect_on_all_associations(:has_and_belongs_to_many).find {|r| r.join_table == key.to_s && value.keys.first.to_s == r.association_foreign_key.to_s }
|
64
|
-
reflection = klass._reflections[klass._reflections[reflection.name.to_s].delegate_reflection.options[:through].to_s]
|
63
|
+
reflection = klass._reflections[klass._reflections[reflection.name.to_s].send(:delegate_reflection).options[:through].to_s]
|
65
64
|
relations << {reflection.name => build_filter_joins(reflection.klass, value)}
|
66
65
|
end
|
67
66
|
end
|
68
67
|
end
|
68
|
+
puts [relations, custom].inspect
|
69
69
|
[relations, custom]
|
70
70
|
end
|
71
71
|
|
@@ -167,9 +167,9 @@ module ActiveRecord
|
|
167
167
|
def expand_filter_for_arel_attribute(column, attribute, key, value)
|
168
168
|
case key.to_sym
|
169
169
|
when :contains
|
170
|
-
attribute.contains(column.array ?
|
170
|
+
attribute.contains(column.array ? convert_filter_value(column, Array(value)) : convert_filter_value(column, value))
|
171
171
|
when :contained_by
|
172
|
-
attribute.contained_by(column.array ?
|
172
|
+
attribute.contained_by(column.array ? convert_filter_value(column, Array(value)) : convert_filter_value(column, value))
|
173
173
|
when :equal_to, :eq
|
174
174
|
attribute.eq(convert_filter_value(column, value))
|
175
175
|
when :excludes
|
@@ -179,7 +179,11 @@ module ActiveRecord
|
|
179
179
|
when :greater_than_or_equal_to, :gteq, :gte
|
180
180
|
attribute.gteq(convert_filter_value(column, value))
|
181
181
|
when :has_key
|
182
|
-
attribute.has_key(
|
182
|
+
attribute.has_key(value)
|
183
|
+
when :has_keys
|
184
|
+
attribute.has_keys(*Array(value))
|
185
|
+
when :has_any_key
|
186
|
+
attribute.has_any_key(*Array(value))
|
183
187
|
when :in
|
184
188
|
attribute.in(convert_filter_value(column, value))
|
185
189
|
when :intersects
|
@@ -220,7 +224,17 @@ module ActiveRecord
|
|
220
224
|
attribute.ts_query(convert_filter_value(column, value))
|
221
225
|
end
|
222
226
|
when :within
|
223
|
-
|
227
|
+
if value.is_a?(String)
|
228
|
+
if /\A[0-9A-F]*\Z/i.match?(value) && (value.start_with?('00') || value.start_with?('01'))
|
229
|
+
attribute.within(Arel::Nodes::HexEncodedBinary.new(value))
|
230
|
+
else
|
231
|
+
attribute.within(Arel::Nodes.build_quoted(value))
|
232
|
+
end
|
233
|
+
elsif value.is_a?(Hash)
|
234
|
+
attribute.within(Arel::Nodes.build_quoted(value))
|
235
|
+
else
|
236
|
+
raise "Not Supported value for within: #{value.inspect}"
|
237
|
+
end
|
224
238
|
else
|
225
239
|
raise "Not Supported: #{key.to_sym}"
|
226
240
|
end
|
@@ -265,7 +279,7 @@ module ActiveRecord
|
|
265
279
|
end
|
266
280
|
|
267
281
|
def expand_filter_for_join_table(relation, value, join_dependency)
|
268
|
-
relation = relation.active_record._reflections[relation.active_record._reflections[relation.name.to_s].delegate_reflection.options[:through].to_s]
|
282
|
+
relation = relation.active_record._reflections[relation.active_record._reflections[relation.name.to_s].send(:delegate_reflection).options[:through].to_s]
|
269
283
|
|
270
284
|
builder = associated_predicate_builder(relation.name.to_sym)
|
271
285
|
if join_dependency
|
@@ -288,8 +302,6 @@ module ActiveRecord
|
|
288
302
|
end
|
289
303
|
|
290
304
|
def build(filters, join_dependency)
|
291
|
-
binds = []
|
292
|
-
|
293
305
|
if filters.is_a?(Hash) || filters.is_a?(Array)
|
294
306
|
# attributes = predicate_builder.resolve_column_aliases(filters)
|
295
307
|
# attributes = klass.send(:expand_hash_conditions_for_aggregates, attributes)
|
@@ -301,7 +313,7 @@ module ActiveRecord
|
|
301
313
|
raise ArgumentError, "Unsupported argument type: #{filters.inspect} (#{filters.class})"
|
302
314
|
end
|
303
315
|
|
304
|
-
WhereClause.new(parts
|
316
|
+
WhereClause.new(parts)
|
305
317
|
end
|
306
318
|
|
307
319
|
protected
|
@@ -314,8 +326,9 @@ end
|
|
314
326
|
class ActiveRecord::Relation
|
315
327
|
module Filter
|
316
328
|
|
317
|
-
def initialize(klass, table, predicate_builder, values
|
329
|
+
def initialize(klass, table: klass.arel_table, predicate_builder: klass.predicate_builder, values: {})
|
318
330
|
@filters = []
|
331
|
+
@join_dependency = nil
|
319
332
|
super
|
320
333
|
end
|
321
334
|
|
@@ -324,14 +337,18 @@ class ActiveRecord::Relation
|
|
324
337
|
super
|
325
338
|
end
|
326
339
|
|
327
|
-
def
|
328
|
-
if
|
329
|
-
|
330
|
-
elsif
|
331
|
-
|
332
|
-
|
333
|
-
|
340
|
+
def clean_filters(value)
|
341
|
+
if value.class.name == 'ActionController::Parameters'.freeze
|
342
|
+
value.to_unsafe_h
|
343
|
+
elsif value.is_a?(Array)
|
344
|
+
value.map { |v| clean_filters(v) }
|
345
|
+
else
|
346
|
+
value
|
334
347
|
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def filter(filters)
|
351
|
+
filters = clean_filters(filters)
|
335
352
|
|
336
353
|
if filters.nil? || filters.empty?
|
337
354
|
self
|
@@ -350,13 +367,13 @@ class ActiveRecord::Relation
|
|
350
367
|
@filter_clause_factory ||= FilterClauseFactory.new(klass, predicate_builder)
|
351
368
|
end
|
352
369
|
|
353
|
-
def build_arel
|
370
|
+
def build_arel(aliases)
|
354
371
|
arel = super
|
355
372
|
build_filters(arel)
|
356
373
|
arel
|
357
374
|
end
|
358
375
|
|
359
|
-
def build_join_query(manager, buckets, join_type)
|
376
|
+
def build_join_query(manager, buckets, join_type, aliases)
|
360
377
|
buckets.default = []
|
361
378
|
|
362
379
|
association_joins = buckets[:association_join]
|
@@ -364,33 +381,36 @@ class ActiveRecord::Relation
|
|
364
381
|
join_nodes = buckets[:join_node].uniq
|
365
382
|
string_joins = buckets[:string_join].map(&:strip).uniq
|
366
383
|
|
367
|
-
join_list = join_nodes + convert_join_strings_to_ast(
|
384
|
+
join_list = join_nodes + convert_join_strings_to_ast(string_joins)
|
385
|
+
alias_tracker = alias_tracker(join_list, aliases)
|
368
386
|
|
369
387
|
join_dependency = ActiveRecord::Associations::JoinDependency.new(
|
370
|
-
|
371
|
-
association_joins,
|
372
|
-
join_list
|
388
|
+
klass, table, association_joins, alias_tracker
|
373
389
|
)
|
374
390
|
|
375
|
-
|
391
|
+
joins = join_dependency.join_constraints(stashed_association_joins, join_type)
|
392
|
+
joins.each { |join| manager.from(join) }
|
393
|
+
# join_infos = join_dependency.join_constraints stashed_association_joins, join_type
|
376
394
|
|
377
|
-
join_infos.each do |info|
|
378
|
-
|
379
|
-
|
380
|
-
end
|
395
|
+
# join_infos.each do |info|
|
396
|
+
# info.joins.each { |join| manager.from(join) }
|
397
|
+
# manager.bind_values.concat info.binds
|
398
|
+
# end
|
399
|
+
|
400
|
+
# manager.join_sources.concat(join_list)
|
381
401
|
|
382
402
|
manager.join_sources.concat(join_list)
|
383
403
|
|
384
|
-
if
|
404
|
+
if klass.connection.class.name != 'ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter'
|
385
405
|
@join_dependency = join_dependency
|
386
406
|
end
|
387
407
|
|
388
|
-
|
408
|
+
alias_tracker.aliases
|
389
409
|
end
|
390
410
|
|
391
411
|
def build_filters(manager)
|
392
412
|
@filters.each do |filters|
|
393
|
-
manager.where(filter_clause_factory.build(filters, @join_dependency&.join_root).ast)
|
413
|
+
manager.where(filter_clause_factory.build(filters, @join_dependency&.send(:join_root)).ast)
|
394
414
|
end
|
395
415
|
end
|
396
416
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,74 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 5.0.0
|
19
|
+
version: 5.2.0.rc1
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 5.0.0
|
26
|
+
version: 5.2.0.rc1
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
28
|
+
name: arel-extensions
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 5.0.0
|
33
|
+
version: 1.6.0
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
46
37
|
requirements:
|
47
38
|
- - "~>"
|
48
39
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 5.0.0
|
40
|
+
version: 1.6.0
|
53
41
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
42
|
+
name: pg
|
55
43
|
requirement: !ruby/object:Gem::Requirement
|
56
44
|
requirements:
|
57
|
-
- - "~>"
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '1.0'
|
60
45
|
- - ">="
|
61
46
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
63
|
-
type: :
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
64
49
|
prerelease: false
|
65
50
|
version_requirements: !ruby/object:Gem::Requirement
|
66
51
|
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '1.0'
|
70
52
|
- - ">="
|
71
53
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
54
|
+
version: '0'
|
73
55
|
- !ruby/object:Gem::Dependency
|
74
|
-
name:
|
56
|
+
name: actionpack
|
75
57
|
requirement: !ruby/object:Gem::Requirement
|
76
58
|
requirements:
|
77
|
-
- - "
|
59
|
+
- - "~>"
|
78
60
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
61
|
+
version: 5.2.0.rc1
|
80
62
|
type: :development
|
81
63
|
prerelease: false
|
82
64
|
version_requirements: !ruby/object:Gem::Requirement
|
83
65
|
requirements:
|
84
|
-
- - "
|
66
|
+
- - "~>"
|
85
67
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
68
|
+
version: 5.2.0.rc1
|
87
69
|
- !ruby/object:Gem::Dependency
|
88
70
|
name: bundler
|
89
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,14 +148,14 @@ dependencies:
|
|
166
148
|
requirements:
|
167
149
|
- - ">="
|
168
150
|
- !ruby/object:Gem::Version
|
169
|
-
version: 5.0.
|
151
|
+
version: 5.2.0.rc1
|
170
152
|
type: :development
|
171
153
|
prerelease: false
|
172
154
|
version_requirements: !ruby/object:Gem::Requirement
|
173
155
|
requirements:
|
174
156
|
- - ">="
|
175
157
|
- !ruby/object:Gem::Version
|
176
|
-
version: 5.0.
|
158
|
+
version: 5.2.0.rc1
|
177
159
|
- !ruby/object:Gem::Dependency
|
178
160
|
name: faker
|
179
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -236,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
236
218
|
version: '0'
|
237
219
|
requirements: []
|
238
220
|
rubyforge_project:
|
239
|
-
rubygems_version: 2.
|
221
|
+
rubygems_version: 2.7.4
|
240
222
|
signing_key:
|
241
223
|
specification_version: 4
|
242
224
|
summary: A safe way to accept user parameters and query against your ActiveRecord
|