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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2957665feb464601c460d97d553e3aac9b4c00229dd971585842e41b03a0ce15
4
- data.tar.gz: e4af3be0d65da1f2f03875ff541c68dc854411d1f80fe2509bc237ce64c39e92
3
+ metadata.gz: 543a8c9e2753e70cbf20bfa1339d9fb694dbddbe7acdaa221dcd61eed414eba3
4
+ data.tar.gz: 4e6c0ee07f07efe8fd4c7c0d690240e1204975b5c17d66e468c7cf46b6b6d4a1
5
5
  SHA512:
6
- metadata.gz: 1114b267101aa3bb1b5486bf35d518cd684119b7b8ba412cdb2f66d0ac1056f1c34b4f2e262a2a0b58610c9dbe855180336a318f1f606a80cadfdefc073ae9d5
7
- data.tar.gz: fbfd4b013dfc3fc73be7295d8392e58e78a229c57809616ebfdc3f6f92932eccbd5a8b45f5787ee68dc5f4488eea2b09d8a3662ead2149ee98b1c7a729eb35a5
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.1
12
+ gem install joiner --version 0.4.2
13
13
  ```
14
14
 
15
15
  ## Usage
@@ -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.1'
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.1'
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
- @alias_tracker = alias_tracker
4
- construct_tables! join_root
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 }
@@ -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
- join_values.join_association_for(path, alias_tracker).tables.first.name
22
+ association_for(path).tables.first.name
23
23
  end
24
24
 
25
25
  def join_values
26
- Joiner::JoinDependency.new model, table, joins_cache.to_a
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.1
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-10 00:00:00.000000000 Z
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.1
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.1
54
+ version: 5.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement