arel-helpers 2.2.0 → 2.3.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
  SHA1:
3
- metadata.gz: 875e70afa83c9d6c1c5b74713162b2eef19c94b1
4
- data.tar.gz: 562a0e972c495904a876f5cfcbf08dbadf71b058
3
+ metadata.gz: 5b9e21c4189a1c32c6361aca598fa70d942f5f2d
4
+ data.tar.gz: 10815ed87668b9fd619cfcdb83c4efef8ea0ad82
5
5
  SHA512:
6
- metadata.gz: 2a364dbb1ccbe4937fa23892678261cdfabc4846111499748f244701f210d7a8996465f80f8d14d7c9add1ab4706f3b4a71d48736caa12ffed20f6b6c5f223f1
7
- data.tar.gz: 746357d316c5eb82e29952f2a5fd54ffebae6e550acb7e8eebdf7fcc9bc6562e37975217afde0f8f4e441495b5789c907d0f2a0e22f398ef06d7913e842de0fe
6
+ metadata.gz: ca0257e7a5fe7e7ca769fd4fb60ab7016f8fd6d7e520e65527b8522db0ab07afb41c3e92ae02f009c73bcf1e0ab93d939b4256e51fa40bc46b24a90656e4c72a
7
+ data.tar.gz: 3a5b57d717d31d94d87008fca7cab200d50dbfff13a25a2f9050c4c24365c4e6d8197f3e491180df7785ca24abc201b2440b7192f6ae2a1dfe142a8a63ff3ba2
data/History.txt CHANGED
@@ -33,3 +33,7 @@
33
33
  == 2.2.0
34
34
 
35
35
  * Adding polymorphic join support for Rails 4.2.
36
+
37
+ == 2.3.0
38
+
39
+ * Adding support for Rails 5 (@vkill #24, @camertron #26)
data/README.md CHANGED
@@ -172,7 +172,7 @@ PostQueryBuilder.new
172
172
 
173
173
  ## Requirements
174
174
 
175
- Requires ActiveRecord >= 3.1.0, <= 4.2.0, tested with Ruby 1.9.3, 2.0.0, and 2.1.0. Depends on SQLite for testing purposes.
175
+ Requires ActiveRecord >= 3.1.0, < 6, tested against Ruby 2.2.4. Depends on SQLite for testing purposes.
176
176
 
177
177
  ## Running Tests
178
178
 
data/arel-helpers.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  if ENV["AR"]
17
17
  s.add_dependency 'activerecord', ENV["AR"]
18
18
  else
19
- s.add_dependency 'activerecord', '>= 3.1.0', '< 5'
19
+ s.add_dependency 'activerecord', '>= 3.1.0', '< 6'
20
20
  end
21
21
 
22
22
  s.require_path = 'lib'
@@ -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, &block)
21
- if ActiveRecord::VERSION::STRING >= '4.2.0'
21
+ if ActiveRecord::VERSION::STRING >= '5.0.0'
22
+ join_association_5_0(table, association, join_type, &block)
23
+ elsif ActiveRecord::VERSION::STRING >= '4.2.0'
22
24
  join_association_4_2(table, association, join_type, &block)
23
25
  elsif ActiveRecord::VERSION::STRING >= '4.1.0'
24
26
  join_association_4_1(table, association, join_type, &block)
@@ -99,6 +101,36 @@ module ArelHelpers
99
101
  join_strings.join(' ')
100
102
  end
101
103
 
104
+ def join_association_5_0(table, association, join_type)
105
+ associations = association.is_a?(Array) ? association : [association]
106
+ join_dependency = ActiveRecord::Associations::JoinDependency.new(table, associations, [])
107
+
108
+ constraints = join_dependency.join_constraints([], join_type)
109
+
110
+ binds = constraints.flat_map do |info|
111
+ prepared_binds = table.connection.prepare_binds_for_database(info.binds)
112
+ prepared_binds.map { |value| table.connection.quote(value) }
113
+ end
114
+
115
+ joins = constraints.flat_map do |constraint|
116
+ constraint.joins.map do |join|
117
+ right = if block_given?
118
+ yield join.left.name.to_sym, join.right
119
+ else
120
+ join.right
121
+ end
122
+
123
+ join_type.new(join.left, right)
124
+ end
125
+ end
126
+
127
+ join_strings = joins.map do |join|
128
+ to_sql(join, table, binds)
129
+ end
130
+
131
+ join_strings.join(' ')
132
+ end
133
+
102
134
  private
103
135
 
104
136
  def to_sql(node, table, binds)
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module ArelHelpers
4
- VERSION = "2.2.0"
4
+ VERSION = "2.3.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.2.0
4
+ version: 2.3.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: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 3.1.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5'
22
+ version: '6'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 3.1.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5'
32
+ version: '6'
33
33
  description: Useful tools to help construct database queries with ActiveRecord and
34
34
  Arel.
35
35
  email:
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.2.3
78
+ rubygems_version: 2.4.5.1
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Useful tools to help construct database queries with ActiveRecord and Arel.