activerecord-where-any-of 1.1.1 → 1.1.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/activerecord-where-any-of.gemspec +2 -2
- data/lib/active_record/where-any-of-mixin-rails-5.rb +45 -5
- 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: 89757a8e0b56e3133e9220af6d3dc0521d49148c3e61036465f7e5d562f93c4f
|
4
|
+
data.tar.gz: a70d52c50687a60db29191d9dbdf5bd3199225e8b456710bf3eab53924cbb3a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70bd1922ac95437f98da846af4580a2dcece793675e84ae3df1fe6bc9ba619ac59b5be7ae0ed35b9a89f68536f4364645e684c889a047e0ed9ed9f88701ce437
|
7
|
+
data.tar.gz: 4c9c0426a3a31e539f94783e14e1882fdf6b74d248e746a777ea80088f3aa758fe8ebc16a48682cb897dc3c8a3fd7eab160383475fe4cd25c590eb2b3554078d
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'activerecord-where-any-of'
|
3
|
-
s.version = '1.1.
|
3
|
+
s.version = '1.1.2'
|
4
4
|
s.license = 'MIT'
|
5
|
-
s.date = '
|
5
|
+
s.date = '2020-05-12'
|
6
6
|
s.summary = 'A simple mixin to ActiveRecord::Base that allows use of OR arel relations.'
|
7
7
|
s.description = 'Should work in Rails 3, 4, & 5. However, in Rails 5 use of #or is prefered.'
|
8
8
|
s.description = File.read(File.expand_path('../README.md', __FILE__))[/Description:\n-+\s*(.*?)\n\n/m, 1]
|
@@ -2,20 +2,60 @@
|
|
2
2
|
module ActiveRecord
|
3
3
|
module WhereAnyOfMixin
|
4
4
|
|
5
|
+
INVALID_RELATION_VALUES = %i[
|
6
|
+
bind
|
7
|
+
eager_load
|
8
|
+
group
|
9
|
+
union_ordering
|
10
|
+
union
|
11
|
+
unscope
|
12
|
+
window
|
13
|
+
with
|
14
|
+
]
|
15
|
+
|
16
|
+
RELATION_VALUES_TO_COPY = %i[
|
17
|
+
includes
|
18
|
+
joined_includes
|
19
|
+
joins
|
20
|
+
left_outer_joins
|
21
|
+
preload
|
22
|
+
references
|
23
|
+
]
|
24
|
+
|
5
25
|
def where_any_of(*conditions)
|
6
26
|
# Rails 5 comes with an #or method for relations, so we can just use that
|
7
27
|
# It is advised that once on Rails 5, this gem should be removed.
|
28
|
+
|
29
|
+
# Do our best to preserve joins from the conditions into the outer relation
|
30
|
+
values_to_copy = {}
|
31
|
+
|
8
32
|
conditions = conditions.map do |c|
|
9
|
-
if c.is_a? Symbol or c.is_a? String
|
10
|
-
|
11
|
-
|
12
|
-
|
33
|
+
c = self.unscoped.send(c) if c.is_a? Symbol or c.is_a? String
|
34
|
+
raise ArgumentError, "Unsupported argument type: #{c.class.name}" unless c.is_a?(ActiveRecord::Relation)
|
35
|
+
|
36
|
+
INVALID_RELATION_VALUES.each do |m|
|
37
|
+
raise ArgumentError, "Unsupported condition contains #{m} values" if c.send("#{m}_values").present?
|
13
38
|
end
|
39
|
+
|
40
|
+
RELATION_VALUES_TO_COPY.each do |m|
|
41
|
+
values = c.send("#{m}_values").presence or next
|
42
|
+
values_to_copy[m] ||= []
|
43
|
+
values_to_copy[m].concat(values)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Only preserve the where clause of the condition
|
47
|
+
c2 = ActiveRecord::Relation.new(c.klass)
|
48
|
+
c2.where_clause = c.where_clause
|
49
|
+
c2
|
14
50
|
end
|
51
|
+
|
15
52
|
if conditions.empty?
|
16
53
|
all.none
|
17
54
|
else
|
18
|
-
|
55
|
+
all_with_copied_values = values_to_copy.reduce(all) do |s, (key, values)|
|
56
|
+
s.send(key, values)
|
57
|
+
end
|
58
|
+
all_with_copied_values.merge conditions.reduce(:or)
|
19
59
|
end
|
20
60
|
end
|
21
61
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-where-any-of
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David McCullars
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|