activerecord_any_of 2.0 → 2.0.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 +4 -4
- data/README.md +6 -1
- data/lib/activerecord_any_of/alternative_builder.rb +10 -2
- data/lib/activerecord_any_of/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ab240782530ddad6e3dd50748a79a0a4a924d856db8b116b41f1e88ccd82b31
|
4
|
+
data.tar.gz: 32063f28c9e58cb7ea8e1c75632321903ffa1cf2a84867953e3f6453908d7570
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0539ca1b4224eb879b000ad86dc650a2f3bb9f7d737ece3e3d7c728540a185ca0aef0332e09b6e6ed377f37dd21357353f12c32f8f536a6c451bf3446b1da94
|
7
|
+
data.tar.gz: 4e14ceda1dbf47a56b07ece910000e9fff1d9400bd147493878a70de0247b0733bc4e5db8bb6beea2d76ae43f32493375e3569aef5fcac270655f9399e46abba
|
data/README.md
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
# ActiverecordAnyOf
|
2
2
|
|
3
|
+
> Warning! Development of activerecord_any_of is now happening on
|
4
|
+
> [Gitlab](https://gitlab.com/oelmekki/activerecord_any_of).
|
5
|
+
>
|
6
|
+
> Please go there for issues and merge requests.
|
7
|
+
|
3
8
|
## Introduction
|
4
9
|
|
5
10
|
This gem provides `#any_of` and `#none_of` on ActiveRecord.
|
6
11
|
|
7
|
-
`#any_of` is inspired by [any_of from mongoid](
|
12
|
+
`#any_of` is inspired by [any_of from mongoid](https://www.mongodb.com/docs/mongoid/current/reference/queries/#any-of-behavior).
|
8
13
|
|
9
14
|
It was released before `#or` was implemented in ActiveRecord. Its main purpose was to both :
|
10
15
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiverecordAnyOf
|
4
|
+
IS_RAILS_6 = ActiveRecord.version.to_s.between?('6', '7')
|
5
|
+
|
4
6
|
# Main class allowing to build alternative conditions for the query.
|
5
7
|
class AlternativeBuilder
|
6
8
|
def initialize(match_type, context, *queries)
|
@@ -110,13 +112,19 @@ module ActiverecordAnyOf
|
|
110
112
|
::Regexp.last_match(2)&.gsub(/=\ \$\d+/, '= ?') or match
|
111
113
|
end
|
112
114
|
end
|
115
|
+
|
116
|
+
def bind_values
|
117
|
+
queries_bind_values.tap do |values|
|
118
|
+
values.map!(&:value) if IS_RAILS_6
|
119
|
+
end
|
120
|
+
end
|
113
121
|
end
|
114
122
|
|
115
123
|
# Returns records that match any of the conditions, ie `#any_of`.
|
116
124
|
class PositiveBuilder < Builder
|
117
125
|
def build
|
118
126
|
relation = if queries && queries_bind_values.any?
|
119
|
-
where([unprepare_query(queries.reduce(:or).to_sql), *
|
127
|
+
where([unprepare_query(queries.reduce(:or).to_sql), *bind_values])
|
120
128
|
else
|
121
129
|
where(queries.reduce(:or).to_sql)
|
122
130
|
end
|
@@ -129,7 +137,7 @@ module ActiverecordAnyOf
|
|
129
137
|
class NegativeBuilder < Builder
|
130
138
|
def build
|
131
139
|
relation = if queries && queries_bind_values.any?
|
132
|
-
where.not([unprepare_query(queries.reduce(:or).to_sql), *
|
140
|
+
where.not([unprepare_query(queries.reduce(:or).to_sql), *bind_values])
|
133
141
|
else
|
134
142
|
where.not(queries.reduce(:or).to_sql)
|
135
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_any_of
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier El Mekki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '8'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8'
|