joiner 0.4.1 → 0.4.2
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/README.md +1 -1
- data/joiner.gemspec +2 -2
- data/lib/joiner/join_dependency.rb +6 -3
- data/lib/joiner/joins.rb +18 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 543a8c9e2753e70cbf20bfa1339d9fb694dbddbe7acdaa221dcd61eed414eba3
|
4
|
+
data.tar.gz: 4e6c0ee07f07efe8fd4c7c0d690240e1204975b5c17d66e468c7cf46b6b6d4a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e65737d1f81fb60fca11d8c5360f25a03f652c516e42481ca9ebbf88df1006408b06d527f43511f16d1f71e1f4ce62332fe8ef6aa47bc6d8946dd1a74320a55a
|
7
|
+
data.tar.gz: 468e756f7560b6dce83e95b59d8dc852e2c87f96436512755101cb63e1bb597061a62f41a56c553cedd698bb33065624a04f729cef02ae3b9c68f7aed056308a
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ If this gem is used by anyone other than myself/Thinking Sphinx, I'll be surpris
|
|
9
9
|
It's a gem - so you can either install it yourself, or add it to the appropriate Gemfile or gemspec.
|
10
10
|
|
11
11
|
```term
|
12
|
-
gem install joiner --version 0.4.
|
12
|
+
gem install joiner --version 0.4.2
|
13
13
|
```
|
14
14
|
|
15
15
|
## Usage
|
data/joiner.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = 'joiner'
|
4
|
-
spec.version = '0.4.
|
4
|
+
spec.version = '0.4.2'
|
5
5
|
spec.authors = ['Pat Allan']
|
6
6
|
spec.email = ['pat@freelancing-gods.com']
|
7
7
|
spec.summary = %q{Builds ActiveRecord joins from association paths}
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.add_runtime_dependency 'activerecord', '>= 5.2.beta1'
|
17
17
|
|
18
18
|
spec.add_development_dependency 'combustion', '~> 0.8'
|
19
|
-
spec.add_development_dependency 'rails', '>= 5.2.
|
19
|
+
spec.add_development_dependency 'rails', '>= 5.2.0'
|
20
20
|
spec.add_development_dependency 'rspec-rails', '~> 3'
|
21
21
|
spec.add_development_dependency 'sqlite3', '~> 1.3.8'
|
22
22
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
class Joiner::JoinDependency < ActiveRecord::Associations::JoinDependency
|
2
|
-
def join_association_for(path, alias_tracker)
|
3
|
-
|
4
|
-
|
2
|
+
def join_association_for(path, alias_tracker = nil)
|
3
|
+
if alias_tracker
|
4
|
+
# ActiveRecord 5.2.1+
|
5
|
+
@alias_tracker = alias_tracker
|
6
|
+
construct_tables! join_root
|
7
|
+
end
|
5
8
|
|
6
9
|
path.inject(join_root) do |node, piece|
|
7
10
|
node.children.detect { |child| child.reflection.name == piece }
|
data/lib/joiner/joins.rb
CHANGED
@@ -19,11 +19,17 @@ class Joiner::Joins
|
|
19
19
|
return model.table_name if path.empty?
|
20
20
|
|
21
21
|
add_join_to path
|
22
|
-
|
22
|
+
association_for(path).tables.first.name
|
23
23
|
end
|
24
24
|
|
25
25
|
def join_values
|
26
|
-
Joiner::JoinDependency.
|
26
|
+
if Joiner::JoinDependency.instance_method(:initialize).arity == 3
|
27
|
+
# ActiveRecord 5.2.1+
|
28
|
+
Joiner::JoinDependency.new model, table, joins_cache.to_a
|
29
|
+
else
|
30
|
+
# ActiveRecord 5.2.0
|
31
|
+
Joiner::JoinDependency.new model, table, joins_cache.to_a, alias_tracker
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
35
|
private
|
@@ -36,6 +42,16 @@ class Joiner::Joins
|
|
36
42
|
)
|
37
43
|
end
|
38
44
|
|
45
|
+
def association_for(path)
|
46
|
+
if Joiner::JoinDependency.instance_method(:initialize).arity == 3
|
47
|
+
# ActiveRecord 5.2.1+
|
48
|
+
join_values.join_association_for path, alias_tracker
|
49
|
+
else
|
50
|
+
# ActiveRecord 5.2.0
|
51
|
+
join_values.join_association_for path
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
39
55
|
def path_as_hash(path)
|
40
56
|
path[0..-2].reverse.inject(path.last) { |key, item| {item => key} }
|
41
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joiner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 5.2.
|
47
|
+
version: 5.2.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 5.2.
|
54
|
+
version: 5.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|