activerecord-filter 5.2.1.1 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -5
- data/lib/active_record/filter.rb +24 -10
- data/lib/active_record/filter/version.rb +1 -1
- metadata +19 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb5558c10ab1700003d9bf88d48bd0d70a68e8cba26e802036f1c540b9e105db
|
4
|
+
data.tar.gz: edabdc23ec140c5cb0ae15078de8f56a8da63e8a813cea36ee9b94b1abf44455
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10393c5284c77f55c91d386e696ad6067841db807286ebd0228c0df4a743a5ee66f283b14b2294e6be3d7c7f705f86079c5f9b46280da6cc57065eb2ed1a25a6
|
7
|
+
data.tar.gz: 8fc0d573ee06224c5c0f9cf245f37011518fac4309689206c5d8f4417efc59ce6e315dc10e36d94af4f00bc9f154d0256e3ba85c52cba6faae6b4cea33a4611f
|
data/README.md
CHANGED
@@ -46,17 +46,21 @@ It can also work with array columns:
|
|
46
46
|
|
47
47
|
```ruby
|
48
48
|
Property.filter(:tags => 'Skyscraper').to_sql
|
49
|
-
# => "...WHERE 'Skyscraper'
|
49
|
+
# => "...WHERE properties.tags = '{'Skyscraper'}'..."
|
50
50
|
|
51
51
|
Property.filter(:tags => ['Skyscraper', 'Brick']).to_sql
|
52
|
-
# => "...WHERE (properties.
|
52
|
+
# => "...WHERE (properties.tags = '{"Skyscraper", "Brick"}')..."
|
53
|
+
|
54
|
+
Property.filter(:tags => {overlaps: ['Skyscraper', 'Brick']}).to_sql
|
55
|
+
# => "...WHERE properties.tags && '{"Skyscraper", "Brick"}')..."
|
56
|
+
|
57
|
+
Property.filter(:tags => {contains: ['Skyscraper', 'Brick']}).to_sql
|
58
|
+
# => "...WHERE accounts.tags @> '{"Skyscraper", "Brick"}')..."
|
59
|
+
|
53
60
|
```
|
54
61
|
It can also sort on relations:
|
55
62
|
|
56
63
|
```ruby
|
57
|
-
Photo.filter(:property => 10).to_sql
|
58
|
-
# => "...WHERE photos.property_id = 5"
|
59
|
-
|
60
64
|
Photo.filter(:property => {name: 'Empire State'}).to_sql
|
61
65
|
# => "...INNER JOIN properties ON properties.id = photos.property_id
|
62
66
|
# => " WHERE properties.name = 'Empire State'"
|
data/lib/active_record/filter.rb
CHANGED
@@ -30,7 +30,8 @@ module ActiveRecord
|
|
30
30
|
class PredicateBuilder # :nodoc:
|
31
31
|
|
32
32
|
def self.filter_joins(klass, filters)
|
33
|
-
|
33
|
+
custom = []
|
34
|
+
[build_filter_joins(klass, filters, [], custom), custom]
|
34
35
|
end
|
35
36
|
|
36
37
|
def self.build_filter_joins(klass, filters, relations=[], custom=[])
|
@@ -40,20 +41,27 @@ module ActiveRecord
|
|
40
41
|
filters.each do |key, value|
|
41
42
|
if klass.filters.has_key?(key.to_sym)
|
42
43
|
js = klass.filters.dig(key.to_sym, :joins)
|
44
|
+
|
43
45
|
if js.is_a?(Array)
|
44
46
|
js.each do |j|
|
45
|
-
if j.is_a?(
|
46
|
-
relations << j
|
47
|
-
else
|
47
|
+
if j.is_a?(String)
|
48
48
|
custom << j
|
49
|
+
else
|
50
|
+
relations << j
|
49
51
|
end
|
50
52
|
end
|
51
53
|
elsif js
|
52
|
-
|
54
|
+
if js.is_a?(String)
|
55
|
+
custom << js
|
56
|
+
else
|
57
|
+
relations << js
|
58
|
+
end
|
53
59
|
end
|
54
60
|
elsif reflection = klass._reflections[key.to_s]
|
55
61
|
if value.is_a?(Hash)
|
56
|
-
relations << {
|
62
|
+
relations << {
|
63
|
+
key => build_filter_joins(reflection.klass, value, [], custom)
|
64
|
+
}
|
57
65
|
elsif value != true && value != false && value != 'true' && value != 'false' && !value.nil?
|
58
66
|
relations << key
|
59
67
|
end
|
@@ -65,7 +73,8 @@ module ActiveRecord
|
|
65
73
|
end
|
66
74
|
end
|
67
75
|
end
|
68
|
-
|
76
|
+
|
77
|
+
relations
|
69
78
|
end
|
70
79
|
|
71
80
|
def build_from_filter_hash(attributes, join_dependency)
|
@@ -216,6 +225,8 @@ module ActiveRecord
|
|
216
225
|
attribute.not_in(convert_filter_value(column, value))
|
217
226
|
when :overlaps
|
218
227
|
attribute.overlaps(convert_filter_value(column, value))
|
228
|
+
when :not_overlaps
|
229
|
+
attribute.not_overlaps(convert_filter_value(column, value))
|
219
230
|
when :ts_match
|
220
231
|
if value.is_a?(Array)
|
221
232
|
attribute.ts_query(*convert_filter_value(column, value))
|
@@ -271,7 +282,7 @@ module ActiveRecord
|
|
271
282
|
|
272
283
|
if join_dependency
|
273
284
|
join_dependency = join_dependency.children.find { |c| c.reflection.name == relation.name }
|
274
|
-
builder.table.instance_variable_set(:@arel_table, join_dependency.tables.first)
|
285
|
+
builder.send(:table).instance_variable_set(:@arel_table, join_dependency.tables.first)
|
275
286
|
end
|
276
287
|
|
277
288
|
builder.build_from_filter_hash(value, join_dependency)
|
@@ -283,7 +294,7 @@ module ActiveRecord
|
|
283
294
|
builder = associated_predicate_builder(relation.name.to_sym)
|
284
295
|
if join_dependency
|
285
296
|
join_dependency = join_dependency.children.find { |c| c.reflection.name == relation.name }
|
286
|
-
builder.table.instance_variable_set(:@arel_table, join_dependency.tables.first)
|
297
|
+
builder.send(:table).instance_variable_set(:@arel_table, join_dependency.tables.first)
|
287
298
|
end
|
288
299
|
builder.build_from_filter_hash(value, join_dependency)
|
289
300
|
end
|
@@ -357,7 +368,10 @@ class ActiveRecord::Relation
|
|
357
368
|
end
|
358
369
|
|
359
370
|
def filter!(filters)
|
360
|
-
|
371
|
+
js = ActiveRecord::PredicateBuilder.filter_joins(klass, filters)
|
372
|
+
js.each do |j|
|
373
|
+
joins!(j) if j.present?
|
374
|
+
end
|
361
375
|
@filters << filters
|
362
376
|
self
|
363
377
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.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: 2019-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0.rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0.rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: arel-extensions
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 6.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 6.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pg
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,36 +56,30 @@ dependencies:
|
|
56
56
|
name: actionpack
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 6.0.0.rc1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 6.0.0.rc1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.11'
|
76
73
|
- - ">="
|
77
74
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
75
|
+
version: '0'
|
79
76
|
type: :development
|
80
77
|
prerelease: false
|
81
78
|
version_requirements: !ruby/object:Gem::Requirement
|
82
79
|
requirements:
|
83
|
-
- - "~>"
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '1.11'
|
86
80
|
- - ">="
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
82
|
+
version: '0'
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: rake
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,14 +142,14 @@ dependencies:
|
|
148
142
|
requirements:
|
149
143
|
- - ">="
|
150
144
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
145
|
+
version: 6.0.0.rc1
|
152
146
|
type: :development
|
153
147
|
prerelease: false
|
154
148
|
version_requirements: !ruby/object:Gem::Requirement
|
155
149
|
requirements:
|
156
150
|
- - ">="
|
157
151
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
152
|
+
version: 6.0.0.rc1
|
159
153
|
- !ruby/object:Gem::Dependency
|
160
154
|
name: faker
|
161
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -217,8 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
211
|
- !ruby/object:Gem::Version
|
218
212
|
version: '0'
|
219
213
|
requirements: []
|
220
|
-
|
221
|
-
rubygems_version: 2.7.6
|
214
|
+
rubygems_version: 3.0.3
|
222
215
|
signing_key:
|
223
216
|
specification_version: 4
|
224
217
|
summary: A safe way to accept user parameters and query against your ActiveRecord
|