arel-helpers 2.6.1 → 2.7.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: 1755b481c031e17e42b6d16db9576749b1fafe58aca6e2b3e4e7a5438e3a8097
4
- data.tar.gz: 161e0bb3c3470f174916eea68c9d07b4c42e53619144869243272a18fa237cd9
3
+ metadata.gz: 6cab403f3acf62a83acc4dcf8b254154cf1062f1bea41f7ef5aff764a5cb0af9
4
+ data.tar.gz: 1eff1af177f5a04a6bdbbced27a3ac84352f6a79a0ec2866c6613064c65c1593
5
5
  SHA512:
6
- metadata.gz: 8864112e0ef6b3d84d6c74b8db83cb87c851bd3b78a73f3655e6d0d833ee218bf41dccd48afaa7e7f94f4f0d918204b7546ad84dad4850e14568ccbc166aa861
7
- data.tar.gz: b7f7d30277375ebc148dbffda0c3b7023ec397cea3135d76666398fd9dde00b62790e0c77349712ff13e33feeba5d200c0e351905f8cfbaa8cae15f6fa3f8300
6
+ metadata.gz: 8a2af67c4bc80ff0d7ec6d95e9c3cb1ac2c56e102e06b70d74e64df045487949ca1a85485dfd14228945ee02ce5ed936bb60bbf38d6b0567283199c278a7d7c4
7
+ data.tar.gz: 14319395dc4944e535be843970fa964923fd1f2cb78fcc15581befd2f1a89ee177e178863fca80233d2c9d780fd9cf6e0bc52498f718afb0b9191ce7d2aad3d5
@@ -18,7 +18,9 @@ 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.0.0'
21
+ if ActiveRecord::VERSION::STRING >= '5.2.0'
22
+ join_association_5_2(table, association, join_type, options, &block)
23
+ elsif ActiveRecord::VERSION::STRING >= '5.0.0'
22
24
  join_association_5_0(table, association, join_type, options, &block)
23
25
  elsif ActiveRecord::VERSION::STRING >= '4.2.0'
24
26
  join_association_4_2(table, association, join_type, options, &block)
@@ -151,6 +153,35 @@ module ArelHelpers
151
153
  join_strings.join(' ')
152
154
  end
153
155
 
156
+ def join_association_5_2(table, association, join_type, options = {})
157
+ aliases = options.fetch(:aliases, [])
158
+ associations = association.is_a?(Array) ? association : [association]
159
+
160
+ alias_tracker = ActiveRecord::Associations::AliasTracker.create(
161
+ table.connection, table.name, {}
162
+ )
163
+
164
+ join_dependency = ActiveRecord::Associations::JoinDependency.new(
165
+ table, table.arel_table, associations, alias_tracker
166
+ )
167
+
168
+ constraints = join_dependency.join_constraints([], join_type)
169
+
170
+ constraints.map do |join|
171
+ right = if block_given?
172
+ yield join.left.name.to_sym, join.right
173
+ else
174
+ join.right
175
+ end
176
+
177
+ if found_alias = find_alias(join.left.name, aliases)
178
+ join.left.table_alias = found_alias.name
179
+ end
180
+
181
+ join_type.new(join.left, right)
182
+ end
183
+ end
184
+
154
185
  private
155
186
 
156
187
  def to_sql(node, table, binds)
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module ArelHelpers
4
- VERSION = '2.6.1'
4
+ VERSION = '2.7.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.6.1
4
+ version: 2.7.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-01-18 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 2.7.3
80
+ rubygems_version: 2.7.6
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Useful tools to help construct database queries with ActiveRecord and Arel.