filterable-by 0.6.1 → 0.6.2
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 +4 -4
- data/Gemfile.lock +5 -5
- data/filterable-by.gemspec +1 -1
- data/lib/filterable_by.rb +2 -1
- data/spec/active_record/filterable_by_spec.rb +4 -0
- data/spec/spec_helper.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a92cb2cde41910a93ed81348238f61031c3e5c8071ab2b118bfceb25307a8c14
|
4
|
+
data.tar.gz: 231b7712b1fe257b34ab63d8a3dc362304c45318984c3eb1a2c8cf004ef2ee44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ca4f69341eaa58f296280b703398c5ce6ad1dcd6551758322c36a03db7f2b9af7e37defeb96c205a5a1520f40e154d4ebd2f5c6110591ccb1505f55f99ac870
|
7
|
+
data.tar.gz: 10691ed7dc8e33b7c6920e8a8e6e670b854bc51d6155baa0923d0cfe363ec2fb8824ed79f3cc635cc9b68f824e3c1951ea32cda8e320e0f40b5ad12fbfa37c2f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
filterable-by (0.6.
|
4
|
+
filterable-by (0.6.2)
|
5
5
|
activerecord
|
6
6
|
activesupport
|
7
7
|
|
@@ -19,12 +19,12 @@ GEM
|
|
19
19
|
minitest (>= 5.1)
|
20
20
|
tzinfo (~> 2.0)
|
21
21
|
ast (2.4.2)
|
22
|
-
concurrent-ruby (1.1.
|
22
|
+
concurrent-ruby (1.1.10)
|
23
23
|
diff-lcs (1.5.0)
|
24
24
|
i18n (1.10.0)
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
26
|
minitest (5.15.0)
|
27
|
-
parallel (1.
|
27
|
+
parallel (1.22.1)
|
28
28
|
parser (3.1.1.0)
|
29
29
|
ast (~> 2.4.1)
|
30
30
|
rainbow (3.1.1)
|
@@ -40,11 +40,11 @@ GEM
|
|
40
40
|
rspec-expectations (3.11.0)
|
41
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
42
|
rspec-support (~> 3.11.0)
|
43
|
-
rspec-mocks (3.11.
|
43
|
+
rspec-mocks (3.11.1)
|
44
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
45
|
rspec-support (~> 3.11.0)
|
46
46
|
rspec-support (3.11.0)
|
47
|
-
rubocop (1.26.
|
47
|
+
rubocop (1.26.1)
|
48
48
|
parallel (~> 1.10)
|
49
49
|
parser (>= 3.1.0.0)
|
50
50
|
rainbow (>= 2.2.2, < 4.0)
|
data/filterable-by.gemspec
CHANGED
data/lib/filterable_by.rb
CHANGED
@@ -58,7 +58,7 @@ module ActiveRecord
|
|
58
58
|
end
|
59
59
|
|
60
60
|
names.each do |name|
|
61
|
-
_filterable_by_config[name.to_s] = block
|
61
|
+
_filterable_by_config[name.to_s] = block
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -74,6 +74,7 @@ module ActiveRecord
|
|
74
74
|
return scope unless hash.respond_to?(:key?) && hash.respond_to?(:[])
|
75
75
|
|
76
76
|
_filterable_by_config.each do |name, block|
|
77
|
+
block = ->(value, **) { where(name.to_sym => value) } if block.nil?
|
77
78
|
scope = FilterableBy.merge(scope, unscoped, hash, name, **opts, &block)
|
78
79
|
break unless scope
|
79
80
|
end
|
@@ -97,4 +97,8 @@ describe ActiveRecord::FilterableBy do
|
|
97
97
|
expect(Comment.filter_by('deprecated_with_opts' => alice.id).pluck(:title)).to match_array(%w[AA AB])
|
98
98
|
expect(Comment.filter_by('deprecated_not' => alice.id).pluck(:title)).to match_array(%w[BA BB])
|
99
99
|
end
|
100
|
+
|
101
|
+
it 'supports abstract classes' do
|
102
|
+
expect(Post.filter_by('author_id' => bob.id).count).to eq(1)
|
103
|
+
end
|
100
104
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -25,10 +25,14 @@ class Author < ActiveRecord::Base
|
|
25
25
|
has_many :posts
|
26
26
|
end
|
27
27
|
|
28
|
-
class
|
28
|
+
class AbstractPost < ActiveRecord::Base
|
29
|
+
self.abstract_class = true
|
30
|
+
filterable_by :author_id
|
31
|
+
end
|
32
|
+
|
33
|
+
class Post < AbstractPost
|
29
34
|
belongs_to :author
|
30
35
|
|
31
|
-
filterable_by :author_id
|
32
36
|
filterable_by :only do |value, **opts|
|
33
37
|
case value
|
34
38
|
when 'me'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filterable-by
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|