joiner 0.3.4 → 0.4.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
- SHA1:
3
- metadata.gz: 7249d05e24afee39fbb2547085068230f6b1d62b
4
- data.tar.gz: 941f72f5d80c3a6c0b8b88684f7a35b77e7461ee
2
+ SHA256:
3
+ metadata.gz: 2c51cc06024d77670209708823110edc631757a07f79c6631fac84329dba5670
4
+ data.tar.gz: 7f6f23f6052291f3fa67782f10ca86345d0755f1c2cb410af45506a3952895dd
5
5
  SHA512:
6
- metadata.gz: 0fd9651d510164f7e5843589678ba62d3f214c67dca6309e4711f71cd8b4200b3e105cd780fdfab14d3a4240d4354fcd95b6568b101d710757da1d093e96600a
7
- data.tar.gz: ff41eaace4916f013c03e7407a65709543251908daab4f3203f723282a9c38c50a35b9767a9b074bb6f7f336bb1042cf30542d8ee179cd08ca868a23228b66fe
6
+ metadata.gz: 5370c3e5b27a66c573e904b70313c28274998c3d47801b166bf4801c3bb053907bad854b13533cb258a545b7cb330e22ba0ca1f84f1937591fcb9c908cb28370
7
+ data.tar.gz: 410f9e1c16727d3ec73c685bbe634e16c93182f63295ac7e117418d663b6d3160e2088515996d683de95634f74b2fa43fcd32698bbb5312accc09b0c32fe5443
data/README.md CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  This gem, abstracted out from [Thinking Sphinx](http://pat.github.io/thinking-sphinx), turns a bunch of association trees from the perspective of a single model and builds a bunch of OUTER JOINs that can be passed into ActiveRecord::Relation's `join` method. You can also find out the generated table aliases for each join, in case you're referring to columns from those joins at some other point.
4
4
 
5
- If this gem is used by anyone other than myself/Thinking Sphinx, I'll be surprised. My reason for pulling it out is so I can more cleanly support Rails' changing approaches to join generation (see v3.1-4.0 compared to v4.1).
5
+ If this gem is used by anyone other than myself/Thinking Sphinx, I'll be surprised. My reason for pulling it out is so I can more cleanly support Rails' changing approaches to join generation (see v3.1-v4.0 compared to v4.1-v5.1 compared to v5.2).
6
6
 
7
7
  ## Installation
8
8
 
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.3.4
12
+ gem install joiner --version 0.4.0
13
13
  ```
14
14
 
15
15
  ## Usage
@@ -49,6 +49,8 @@ path.model #=> Comment
49
49
 
50
50
  ## Contributing
51
51
 
52
+ Please note that this project now has a [Contributor Code of Conduct](http://contributor-covenant.org/version/1/0/0/). By participating in this project you agree to abide by its terms.
53
+
52
54
  1. Fork it
53
55
  2. Create your feature branch (`git checkout -b my-new-feature`)
54
56
  3. Commit your changes (`git commit -am 'Add some feature'`)
@@ -57,4 +59,4 @@ path.model #=> Comment
57
59
 
58
60
  ## Licence
59
61
 
60
- Copyright (c) 2013, Joiner is developed and maintained by [Pat Allan](http://freelancing-gods.com), and is released under the open MIT Licence.
62
+ Copyright (c) 2013-2018, Joiner is developed and maintained by [Pat Allan](http://freelancing-gods.com), and is released under the open MIT Licence.
@@ -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.3.4'
4
+ spec.version = '0.4.0'
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}
@@ -13,10 +13,10 @@ Gem::Specification.new do |spec|
13
13
  spec.test_files = spec.files.grep(%r{^(spec)/})
14
14
  spec.require_paths = ['lib']
15
15
 
16
- spec.add_runtime_dependency 'activerecord', '>= 4.1.0'
16
+ spec.add_runtime_dependency 'activerecord', '>= 5.2.beta1'
17
17
 
18
- spec.add_development_dependency 'combustion', '~> 0.5.1'
19
- spec.add_development_dependency 'rails', '>= 4.1.2'
20
- spec.add_development_dependency 'rspec-rails', '~> 2.14.1'
18
+ spec.add_development_dependency 'combustion', '~> 0.8'
19
+ spec.add_development_dependency 'rails', '>= 5.2.0'
20
+ spec.add_development_dependency 'rspec-rails', '~> 3'
21
21
  spec.add_development_dependency 'sqlite3', '~> 1.3.8'
22
22
  end
@@ -1,9 +1,11 @@
1
1
  require 'set'
2
+ require 'active_record'
2
3
 
3
4
  module Joiner
4
5
  class AssociationNotFound < StandardError
5
6
  end
6
7
  end
7
8
 
9
+ require 'joiner/join_dependency'
8
10
  require 'joiner/joins'
9
11
  require 'joiner/path'
@@ -0,0 +1,7 @@
1
+ class Joiner::JoinDependency < ActiveRecord::Associations::JoinDependency
2
+ def join_association_for(path)
3
+ path.inject(join_root) do |node, piece|
4
+ node.children.detect { |child| child.reflection.name == piece }
5
+ end
6
+ end
7
+ end
@@ -2,11 +2,7 @@ require 'active_record'
2
2
  require 'active_support/ordered_hash'
3
3
 
4
4
  class Joiner::Joins
5
- JoinDependency = ActiveRecord::Associations::JoinDependency
6
- JoinAssociation = JoinDependency::JoinAssociation
7
-
8
- attr_reader :model
9
- attr_accessor :join_association_class
5
+ attr_reader :model
10
6
 
11
7
  def initialize(model)
12
8
  @model = model
@@ -23,35 +19,28 @@ class Joiner::Joins
23
19
  return model.table_name if path.empty?
24
20
 
25
21
  add_join_to path
26
- join_association_for(path).tables.first.name
22
+ join_values.join_association_for(path).tables.first.name
27
23
  end
28
24
 
29
25
  def join_values
30
- switch_join_dependency join_association_class
31
- result = JoinDependency.new model, joins_cache.to_a, []
32
- switch_join_dependency JoinAssociation
33
-
34
- result
26
+ Joiner::JoinDependency.new model, table, joins_cache.to_a, alias_tracker
35
27
  end
36
28
 
37
29
  private
38
30
 
39
31
  attr_reader :joins_cache
40
32
 
41
- def join_association_for(path)
42
- path.inject(join_values.join_root) do |node, piece|
43
- node.children.detect { |child| child.reflection.name == piece }
44
- end
33
+ def alias_tracker
34
+ ActiveRecord::Associations::AliasTracker.create(
35
+ model.connection, table.name, []
36
+ )
45
37
  end
46
38
 
47
39
  def path_as_hash(path)
48
40
  path[0..-2].reverse.inject(path.last) { |key, item| {item => key} }
49
41
  end
50
42
 
51
- def switch_join_dependency(klass)
52
- return unless join_association_class
53
-
54
- JoinDependency.send :remove_const, :JoinAssociation
55
- JoinDependency.const_set :JoinAssociation, klass
43
+ def table
44
+ @table ||= model.arel_table
56
45
  end
57
46
  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.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2018-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: 5.2.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.0
26
+ version: 5.2.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: combustion
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.1
33
+ version: '0.8'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.1
40
+ version: '0.8'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 4.1.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: 4.1.2
54
+ version: 5.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.14.1
61
+ version: '3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 2.14.1
68
+ version: '3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +95,7 @@ files:
95
95
  - Rakefile
96
96
  - joiner.gemspec
97
97
  - lib/joiner.rb
98
+ - lib/joiner/join_dependency.rb
98
99
  - lib/joiner/joins.rb
99
100
  - lib/joiner/path.rb
100
101
  - spec/acceptance/joiner_spec.rb
@@ -126,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  version: '0'
127
128
  requirements: []
128
129
  rubyforge_project:
129
- rubygems_version: 2.3.0
130
+ rubygems_version: 2.7.6
130
131
  signing_key:
131
132
  specification_version: 4
132
133
  summary: Builds ActiveRecord joins from association paths