active_record_extended 3.1.0 → 3.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ecf1213e83b4ef3e177957d668d253541a1de09a784fbc2007a782661acc647
4
- data.tar.gz: 4fbf39a2fdb8695a7ed787a672c4f0b0988e7b854757955b3883fc546fdcb3d9
3
+ metadata.gz: 2fad3f098c418432644e9a1038c9adba5c4c0a3d5edd29571a5eced2a413a8ec
4
+ data.tar.gz: fd77f4b03e3273ee84d74c87c7f2cd3264034173a7c81e91ca6ccb6a5efc733a
5
5
  SHA512:
6
- metadata.gz: 3afca0a92e015572b4e318a3457f9910f43cefad6ab3286a5847bf76c4e659eb3bbdcd0ddce68bd1b1fe876866bfbcf959686e51fb55598bb38c936716715161
7
- data.tar.gz: 70c7e5c95251002333b2453688f1d2f3e5fcab8c6866837969ed2570f3432771efbe56cc33a7df11ef4f47b29f18aff226fb5695ff3453a8d38f6e48b1fecd62
6
+ metadata.gz: e91ff546cb1c33fecd49d76cdb1a26ca7d58b7da7c30726d56559fd6a797be45c7054171e1bd5be9c70ea7604558e9df837ff84c3fbd9ae744dd37f511b00f43
7
+ data.tar.gz: c5745c586abbe365133638fe52e19603170a053dbaab6e451e416a4f5d58ab456468ce8a7f276d83f3d28f10d0ff9c01b18ec3c4a1e60d74f4935e72034d4b7c
data/README.md CHANGED
@@ -52,12 +52,12 @@ Active Record Extended is essentially providing users with the other half of Pos
52
52
  ## Compatibility
53
53
 
54
54
  This package is designed align and work with any officially supported Ruby and Rails versions.
55
- - Minimum Ruby Version: 2.5.x **(EOL warning!)**
55
+ - Minimum Ruby Version: 2.7.x **(EOL warning!)**
56
56
  - Minimum Rails Version: 5.2.x **(EOL warning!)**
57
57
  - Minimum Postgres Version: 11.x **(EOL warning!)**
58
- - Latest Ruby supported: 3.1.x
58
+ - Latest Ruby supported: 3.2.x
59
59
  - Latest Rails supported: 7.0.x
60
- - Postgres: 11-current(14) (probably works with most older versions to a certain point)
60
+ - Postgres: 11-current(15) (probably works with most older versions to a certain point)
61
61
 
62
62
  ## Installation
63
63
 
@@ -5,23 +5,15 @@ module ActiveRecordExtended
5
5
  module AnyOf
6
6
  def any_of(*queries)
7
7
  queries = hash_map_queries(queries)
8
- build_query(queries) do |arel_query, binds|
9
- if binds.any?
10
- @scope.where(unprepared_query(arel_query.to_sql), *binds)
11
- else
12
- @scope.where(arel_query)
13
- end
8
+ build_query(queries) do |arel_query|
9
+ @scope.where(arel_query)
14
10
  end
15
11
  end
16
12
 
17
13
  def none_of(*queries)
18
14
  queries = hash_map_queries(queries)
19
- build_query(queries) do |arel_query, binds|
20
- if binds.any?
21
- @scope.where.not(unprepared_query(arel_query.to_sql), *binds)
22
- else
23
- @scope.where.not(arel_query)
24
- end
15
+ build_query(queries) do |arel_query|
16
+ @scope.where.not(arel_query)
25
17
  end
26
18
  end
27
19
 
@@ -37,7 +29,7 @@ module ActiveRecordExtended
37
29
 
38
30
  def build_query(queries)
39
31
  query_map = construct_query_mappings(queries)
40
- query = yield(query_map[:arel_query], query_map[:binds])
32
+ query = yield(query_map[:arel_query])
41
33
  query
42
34
  .joins(query_map[:joins].to_a)
43
35
  .includes(query_map[:includes].to_a)
@@ -51,29 +43,13 @@ module ActiveRecordExtended
51
43
  query_map[:joins] << translate_reference(query.joins_values) if query.joins_values.any?
52
44
  query_map[:includes] << translate_reference(query.includes_values) if query.includes_values.any?
53
45
  query_map[:references] << translate_reference(query.references_values) if query.references_values.any?
54
- query_map[:binds] += bind_attributes(query)
55
46
  query.arel.constraints.reduce(:and)
56
47
  end.reduce(:or)
57
48
  end
58
49
  end
59
50
 
60
- # Rails 5.1 fix
61
- # In Rails 5.2 the arel table maintains attribute binds
62
- def bind_attributes(query)
63
- return [] unless query.respond_to?(:bound_attributes)
64
-
65
- query.bound_attributes.map(&:value)
66
- end
67
-
68
- # Rails 5.1 fix
69
- def unprepared_query(query)
70
- query.gsub(/((?<!\\)'.*?(?<!\\)'|(?<!\\)".*?(?<!\\)")|(=\ \$\d+)/) do |match|
71
- Regexp.last_match(2)&.gsub(/=\ \$\d+/, "= ?") || match
72
- end
73
- end
74
-
75
51
  def translate_reference(reference)
76
- reference.map { |ref| ref.try(:to_sql) || ref }.compact
52
+ reference.filter_map { |ref| ref.try(:to_sql) || ref }
77
53
  end
78
54
 
79
55
  def generate_where_clause(query)
@@ -107,7 +107,7 @@ module ActiveRecordExtended
107
107
  end
108
108
 
109
109
  def union(opts = :chain, *args)
110
- return UnionChain.new(spawn) if opts == :chain
110
+ return UnionChain.new(spawn) if :chain == opts
111
111
 
112
112
  opts.nil? ? self : spawn.union!(opts, *args, chain_method: __callee__)
113
113
  end
@@ -121,7 +121,7 @@ module ActiveRecordExtended
121
121
  def union!(opts = :chain, *args, chain_method: :union)
122
122
  union_chain = UnionChain.new(self)
123
123
  chain_method ||= :union
124
- return union_chain if opts == :chain
124
+ return union_chain if :chain == opts
125
125
 
126
126
  union_chain.public_send(chain_method, *([opts] + args))
127
127
  end
@@ -161,12 +161,17 @@ module ActiveRecordExtended
161
161
  end
162
162
 
163
163
  # @param [Hash, WithCTE] opts
164
- def with!(opts = :chain, *_rest)
165
- return WithChain.new(self) if opts == :chain
166
-
167
- tap do |scope|
168
- scope.cte ||= WithCTE.new(self)
169
- scope.cte.pipe_cte_with!(opts)
164
+ def with!(opts = :chain, *rest)
165
+ case opts
166
+ when :chain
167
+ WithChain.new(self)
168
+ when :recursive
169
+ WithChain.new(self).recursive(*rest)
170
+ else
171
+ tap do |scope|
172
+ scope.cte ||= WithCTE.new(self)
173
+ scope.cte.pipe_cte_with!(opts)
174
+ end
170
175
  end
171
176
  end
172
177
 
@@ -176,7 +181,6 @@ module ActiveRecordExtended
176
181
  cte_statements = cte.map do |name, expression|
177
182
  grouped_expression = cte.generate_grouping(expression)
178
183
  cte_name = cte.to_arel_sql(cte.double_quote(name.to_s))
179
-
180
184
  grouped_expression = add_materialized_modifier(grouped_expression, cte, name)
181
185
 
182
186
  Arel::Nodes::As.new(cte_name, grouped_expression)
@@ -193,9 +197,9 @@ module ActiveRecordExtended
193
197
 
194
198
  def add_materialized_modifier(expression, cte, name)
195
199
  if cte.materialized_key?(name)
196
- Arel::Nodes::SqlLiteral.new("MATERIALIZED #{expression.to_sql}")
200
+ Arel.sql("MATERIALIZED #{expression.to_sql}")
197
201
  elsif cte.not_materialized_key?(name)
198
- Arel::Nodes::SqlLiteral.new("NOT MATERIALIZED #{expression.to_sql}")
202
+ Arel.sql("NOT MATERIALIZED #{expression.to_sql}")
199
203
  else
200
204
  expression
201
205
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordExtended
4
- VERSION = "3.1.0"
4
+ VERSION = "3.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_extended
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Protacio-Karaszi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-12-01 00:00:00.000000000 Z
13
+ date: 2023-02-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-sqlimit
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.0.5
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.0.5
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: simplecov
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -167,14 +181,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
181
  requirements:
168
182
  - - ">="
169
183
  - !ruby/object:Gem::Version
170
- version: '2.5'
184
+ version: '2.7'
171
185
  required_rubygems_version: !ruby/object:Gem::Requirement
172
186
  requirements:
173
187
  - - ">="
174
188
  - !ruby/object:Gem::Version
175
189
  version: '0'
176
190
  requirements: []
177
- rubygems_version: 3.3.19
191
+ rubygems_version: 3.4.1
178
192
  signing_key:
179
193
  specification_version: 4
180
194
  summary: Adds extended functionality to Activerecord Postgres implementation