arel-helpers 2.2.0 → 2.3.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 +4 -4
- data/History.txt +4 -0
- data/README.md +1 -1
- data/arel-helpers.gemspec +1 -1
- data/lib/arel-helpers/join_association.rb +33 -1
- data/lib/arel-helpers/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b9e21c4189a1c32c6361aca598fa70d942f5f2d
|
4
|
+
data.tar.gz: 10815ed87668b9fd619cfcdb83c4efef8ea0ad82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca0257e7a5fe7e7ca769fd4fb60ab7016f8fd6d7e520e65527b8522db0ab07afb41c3e92ae02f009c73bcf1e0ab93d939b4256e51fa40bc46b24a90656e4c72a
|
7
|
+
data.tar.gz: 3a5b57d717d31d94d87008fca7cab200d50dbfff13a25a2f9050c4c24365c4e6d8197f3e491180df7785ca24abc201b2440b7192f6ae2a1dfe142a8a63ff3ba2
|
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -172,7 +172,7 @@ PostQueryBuilder.new
|
|
172
172
|
|
173
173
|
## Requirements
|
174
174
|
|
175
|
-
Requires ActiveRecord >= 3.1.0,
|
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
@@ -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 >= '
|
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)
|
data/lib/arel-helpers/version.rb
CHANGED
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.
|
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-
|
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: '
|
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: '
|
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.
|
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.
|