arel-helpers 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cab403f3acf62a83acc4dcf8b254154cf1062f1bea41f7ef5aff764a5cb0af9
4
- data.tar.gz: 1eff1af177f5a04a6bdbbced27a3ac84352f6a79a0ec2866c6613064c65c1593
3
+ metadata.gz: e692ef35ca5dfd967971eeb47c87ef93b6ca21c142e03ecb29b608c1e8e533e0
4
+ data.tar.gz: 719115c3d5f7a9c86d89d6bc720e390906eac6a9d5b60d29c19bebe751aa8c5b
5
5
  SHA512:
6
- metadata.gz: 8a2af67c4bc80ff0d7ec6d95e9c3cb1ac2c56e102e06b70d74e64df045487949ca1a85485dfd14228945ee02ce5ed936bb60bbf38d6b0567283199c278a7d7c4
7
- data.tar.gz: 14319395dc4944e535be843970fa964923fd1f2cb78fcc15581befd2f1a89ee177e178863fca80233d2c9d780fd9cf6e0bc52498f718afb0b9191ce7d2aad3d5
6
+ metadata.gz: 946f6a173a8a3da761ad79b9a416cc7b7871ba0ce879ecd0cb32b2348199c65109df1f7ebee1ec438bdf3cf443d840282935e97d56eed009ac54a31b79cb9d83
7
+ data.tar.gz: 346d3fcbe5be8208734ca9a35f47870531524d008f8e67d307912eb3582d134b2b51c5a721ff31b5488efb519ade8c6c7830db509aa38450280e764147974527
@@ -18,13 +18,15 @@ module ArelHelpers
18
18
  # This method encapsulates that functionality and yields an intermediate object for chaining.
19
19
  # It also allows you to use an outer join instead of the default inner via the join_type arg.
20
20
  def join_association(table, association, join_type = Arel::Nodes::InnerJoin, options = {}, &block)
21
- if ActiveRecord::VERSION::STRING >= '5.2.0'
21
+ if version >= '5.2.1'
22
+ join_association_5_2_1(table, association, join_type, options, &block)
23
+ elsif version >= '5.2.0'
22
24
  join_association_5_2(table, association, join_type, options, &block)
23
- elsif ActiveRecord::VERSION::STRING >= '5.0.0'
25
+ elsif version >= '5.0.0'
24
26
  join_association_5_0(table, association, join_type, options, &block)
25
- elsif ActiveRecord::VERSION::STRING >= '4.2.0'
27
+ elsif version >= '4.2.0'
26
28
  join_association_4_2(table, association, join_type, options, &block)
27
- elsif ActiveRecord::VERSION::STRING >= '4.1.0'
29
+ elsif version >= '4.1.0'
28
30
  join_association_4_1(table, association, join_type, options, &block)
29
31
  else
30
32
  join_association_3_1(table, association, join_type, options, &block)
@@ -33,6 +35,10 @@ module ArelHelpers
33
35
 
34
36
  private
35
37
 
38
+ def version
39
+ ActiveRecord::VERSION::STRING
40
+ end
41
+
36
42
  def join_association_3_1(table, association, join_type, options = {})
37
43
  aliases = options.fetch(:aliases, {})
38
44
  associations = association.is_a?(Array) ? association : [association]
@@ -182,6 +188,35 @@ module ArelHelpers
182
188
  end
183
189
  end
184
190
 
191
+ def join_association_5_2_1(table, association, join_type, options = {})
192
+ aliases = options.fetch(:aliases, [])
193
+ associations = association.is_a?(Array) ? association : [association]
194
+
195
+ alias_tracker = ActiveRecord::Associations::AliasTracker.create(
196
+ table.connection, table.name, {}
197
+ )
198
+
199
+ join_dependency = ActiveRecord::Associations::JoinDependency.new(
200
+ table, table.arel_table, associations
201
+ )
202
+
203
+ constraints = join_dependency.join_constraints([], join_type, alias_tracker)
204
+
205
+ constraints.map do |join|
206
+ right = if block_given?
207
+ yield join.left.name.to_sym, join.right
208
+ else
209
+ join.right
210
+ end
211
+
212
+ if found_alias = find_alias(join.left.name, aliases)
213
+ join.left.table_alias = found_alias.name
214
+ end
215
+
216
+ join_type.new(join.left, right)
217
+ end
218
+ end
219
+
185
220
  private
186
221
 
187
222
  def to_sql(node, table, binds)
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module ArelHelpers
4
- VERSION = '2.7.0'
4
+ VERSION = '2.8.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-10 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord