left_join 0.1.0 → 0.2.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: c226ac4666aed1a80fcc689ace520632c2ea831f
4
- data.tar.gz: 402f3e1674f93254b76a6c79bb01c4617899b96e
3
+ metadata.gz: cbd1e1087f2324c39141cdd48a47dd51e89b842c
4
+ data.tar.gz: 561a76881876900b8f5d71b0026d1c899724324c
5
5
  SHA512:
6
- metadata.gz: acf5969fefa5c6a2a89ad968e45e6e860dd645582e361be7716ce543f5c0379ebde0620c0c3aa6f45d39994bc946ed2636c7d0360b571cdced988e5c4e62777f
7
- data.tar.gz: 85e33528364c50b89d5c02ef42882d5111e69263bcecbe31b4625adeb8fcc5ab81021edd63dd2cdb698c54538b7eced80e8637b22ce6b27db467aa0fcae5c2f9
6
+ metadata.gz: 14c930afa5688b049a8c021e7d98d4b67f3132e8ed51834b4df83daf38934a6d52d2400f94ae0c98dc397bb45e4956facd7404b043e05df811ea0849ab887457
7
+ data.tar.gz: 62f3d176a8f5fbb308bd81317d559386c52dffdd61dee2510c100f409a81935e5698cf689042e150f2d47c50d47ba4570bf7f67b9289e57e4de08a21eecc0174
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ group :development do
6
6
  gem 'rspec', '~> 3.3.0'
7
7
  gem 'rdoc', '~> 3.12'
8
8
  gem 'bundler', '~> 1.0'
9
- gem 'jeweler', '~> 2.0.1'
9
+ gem 'jeweler', '~> 2.1.0'
10
10
  gem 'simplecov', '>= 0'
11
11
  gem 'sqlite3'
12
12
  gem 'activerecord'
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (4.2.4)
5
- activesupport (= 4.2.4)
4
+ activemodel (4.2.6)
5
+ activesupport (= 4.2.6)
6
6
  builder (~> 3.1)
7
- activerecord (4.2.4)
8
- activemodel (= 4.2.4)
9
- activesupport (= 4.2.4)
7
+ activerecord (4.2.6)
8
+ activemodel (= 4.2.6)
9
+ activesupport (= 4.2.6)
10
10
  arel (~> 6.0)
11
- activesupport (4.2.4)
11
+ activesupport (4.2.6)
12
12
  i18n (~> 0.7)
13
13
  json (~> 1.7, >= 1.7.7)
14
14
  minitest (~> 5.1)
15
15
  thread_safe (~> 0.3, >= 0.3.4)
16
16
  tzinfo (~> 1.1)
17
- addressable (2.3.8)
17
+ addressable (2.4.0)
18
18
  arel (6.0.3)
19
19
  builder (3.2.2)
20
20
  descendants_tracker (0.0.4)
@@ -23,19 +23,18 @@ GEM
23
23
  docile (1.1.5)
24
24
  faraday (0.9.2)
25
25
  multipart-post (>= 1.2, < 3)
26
- git (1.2.9.1)
27
- github_api (0.12.4)
28
- addressable (~> 2.3)
26
+ git (1.3.0)
27
+ github_api (0.13.1)
28
+ addressable (~> 2.4.0)
29
29
  descendants_tracker (~> 0.0.4)
30
30
  faraday (~> 0.8, < 0.10)
31
31
  hashie (>= 3.4)
32
32
  multi_json (>= 1.7.5, < 2.0)
33
- nokogiri (~> 1.6.6)
34
33
  oauth2
35
- hashie (3.4.2)
36
- highline (1.7.7)
34
+ hashie (3.4.4)
35
+ highline (1.7.8)
37
36
  i18n (0.7.0)
38
- jeweler (2.0.1)
37
+ jeweler (2.1.1)
39
38
  builder
40
39
  bundler (>= 1.0)
41
40
  git (>= 1.2.5)
@@ -44,23 +43,24 @@ GEM
44
43
  nokogiri (>= 1.5.10)
45
44
  rake
46
45
  rdoc
46
+ semver
47
47
  json (1.8.3)
48
48
  jwt (1.5.1)
49
- mini_portile (0.6.2)
50
- minitest (5.8.0)
51
- multi_json (1.11.2)
49
+ mini_portile2 (2.0.0)
50
+ minitest (5.9.0)
51
+ multi_json (1.12.0)
52
52
  multi_xml (0.5.5)
53
53
  multipart-post (2.0.0)
54
- nokogiri (1.6.6.2)
55
- mini_portile (~> 0.6.0)
56
- oauth2 (1.0.0)
54
+ nokogiri (1.6.7.2)
55
+ mini_portile2 (~> 2.0.0.rc2)
56
+ oauth2 (1.1.0)
57
57
  faraday (>= 0.8, < 0.10)
58
- jwt (~> 1.0)
58
+ jwt (~> 1.0, < 1.5.2)
59
59
  multi_json (~> 1.3)
60
60
  multi_xml (~> 0.5)
61
- rack (~> 1.2)
61
+ rack (>= 1.2, < 3)
62
62
  rack (1.6.4)
63
- rake (10.4.2)
63
+ rake (11.1.2)
64
64
  rdoc (3.12.2)
65
65
  json (~> 1.4)
66
66
  rspec (3.3.0)
@@ -76,12 +76,13 @@ GEM
76
76
  diff-lcs (>= 1.2.0, < 2.0)
77
77
  rspec-support (~> 3.3.0)
78
78
  rspec-support (3.3.0)
79
- simplecov (0.10.0)
79
+ semver (1.0.1)
80
+ simplecov (0.11.2)
80
81
  docile (~> 1.1.0)
81
82
  json (~> 1.8)
82
83
  simplecov-html (~> 0.10.0)
83
84
  simplecov-html (0.10.0)
84
- sqlite3 (1.3.10)
85
+ sqlite3 (1.3.11)
85
86
  thread_safe (0.3.5)
86
87
  tzinfo (1.2.2)
87
88
  thread_safe (~> 0.1)
@@ -92,11 +93,11 @@ PLATFORMS
92
93
  DEPENDENCIES
93
94
  activerecord
94
95
  bundler (~> 1.0)
95
- jeweler (~> 2.0.1)
96
+ jeweler (~> 2.1.0)
96
97
  rdoc (~> 3.12)
97
98
  rspec (~> 3.3.0)
98
99
  simplecov
99
100
  sqlite3
100
101
 
101
102
  BUNDLED WITH
102
- 1.10.6
103
+ 1.12.2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/left_join.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: left_join 0.1.0 ruby lib
5
+ # stub: left_join 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "left_join"
9
- s.version = "0.1.0"
9
+ s.version = "0.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Diego Aguir Selzlein"]
14
- s.date = "2015-10-09"
14
+ s.date = "2016-05-18"
15
15
  s.description = "This gem helps doing LEFT JOIN's between ActiveRecord associations"
16
16
  s.email = "diegoselzlein@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -30,13 +30,12 @@ Gem::Specification.new do |s|
30
30
  "left_join.gemspec",
31
31
  "lib/left_join.rb",
32
32
  "lib/left_join/adapters/active_record_adapter.rb",
33
- "lib/left_join/node.rb",
34
33
  "spec/left_join_spec.rb",
35
34
  "spec/spec_helper.rb"
36
35
  ]
37
36
  s.homepage = "http://github.com/nerde/left_join"
38
37
  s.licenses = ["MIT"]
39
- s.rubygems_version = "2.4.5.1"
38
+ s.rubygems_version = "2.5.1"
40
39
  s.summary = "LEFT JOIN with ActiveRecord"
41
40
 
42
41
  if s.respond_to? :specification_version then
@@ -46,7 +45,7 @@ Gem::Specification.new do |s|
46
45
  s.add_development_dependency(%q<rspec>, ["~> 3.3.0"])
47
46
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
47
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
49
- s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 2.1.0"])
50
49
  s.add_development_dependency(%q<simplecov>, [">= 0"])
51
50
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
52
51
  s.add_development_dependency(%q<activerecord>, [">= 0"])
@@ -54,7 +53,7 @@ Gem::Specification.new do |s|
54
53
  s.add_dependency(%q<rspec>, ["~> 3.3.0"])
55
54
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
56
55
  s.add_dependency(%q<bundler>, ["~> 1.0"])
57
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
56
+ s.add_dependency(%q<jeweler>, ["~> 2.1.0"])
58
57
  s.add_dependency(%q<simplecov>, [">= 0"])
59
58
  s.add_dependency(%q<sqlite3>, [">= 0"])
60
59
  s.add_dependency(%q<activerecord>, [">= 0"])
@@ -63,7 +62,7 @@ Gem::Specification.new do |s|
63
62
  s.add_dependency(%q<rspec>, ["~> 3.3.0"])
64
63
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
64
  s.add_dependency(%q<bundler>, ["~> 1.0"])
66
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
65
+ s.add_dependency(%q<jeweler>, ["~> 2.1.0"])
67
66
  s.add_dependency(%q<simplecov>, [">= 0"])
68
67
  s.add_dependency(%q<sqlite3>, [">= 0"])
69
68
  s.add_dependency(%q<activerecord>, [">= 0"])
data/lib/left_join.rb CHANGED
@@ -1,23 +1,4 @@
1
1
  module LeftJoin
2
- autoload :Node, 'left_join/node'
3
-
4
- def self.parse_to_nodes(arguments, context)
5
- [].tap do |result|
6
- case arguments
7
- when Hash
8
- arguments.each do |key, value|
9
- result.concat parse_to_nodes(key, context)
10
- result.concat parse_to_nodes(value, context.left_join_subcontext(key))
11
- end
12
- when Array
13
- arguments.each do |value|
14
- result.concat parse_to_nodes(value, context)
15
- end
16
- else
17
- result << context.node_for_left_join(arguments)
18
- end
19
- end
20
- end
21
2
  end
22
3
 
23
4
  require 'left_join/adapters/active_record_adapter'
@@ -12,32 +12,10 @@ module LeftJoin
12
12
  #
13
13
  # Book.left_join(category: :master_category)
14
14
  def left_join(*columns)
15
- LeftJoin.parse_to_nodes(columns, self).inject(all) do |acc, association|
16
- table = association.active_record.arel_table
17
- join_table = association.klass.arel_table
18
- foreign_key = association.foreign_key
19
- primary_key = association.association_primary_key.to_sym
20
- unless association.belongs_to?
21
- foreign_key, primary_key = primary_key, foreign_key
22
- end
23
-
24
- arel_join = table.join(join_table, Arel::Nodes::OuterJoin) \
25
- .on(table[foreign_key].eq(join_table[primary_key]))
26
- acc.joins(arel_join.join_sources)
27
- end
28
- end
29
-
30
- def node_for_left_join(key)
31
- reflect_on_association(key) ||
32
- fail("#{self} has no association: #{key}.")
33
- end
34
-
35
- def left_join_subcontext(key)
36
- node_for_left_join(key).klass
15
+ joins(ActiveRecord::Associations::JoinDependency.new(self, columns, []))
37
16
  end
38
17
  end
39
18
 
40
19
  ActiveRecord::Base.extend ActiveRecordAdapter if defined?(ActiveRecord)
41
20
  end
42
21
  end
43
-
@@ -11,40 +11,33 @@ end
11
11
  class Book < ActiveRecord::Base
12
12
  belongs_to :author
13
13
  belongs_to :category
14
+ has_many :tags, as: :taggable
15
+ end
16
+
17
+ class Tag < ActiveRecord::Base
18
+ belongs_to :taggable, polymorphic: true
14
19
  end
15
20
 
16
21
  describe 'LeftJoin' do
17
22
  it 'generates a LEFT OUTER JOIN SQL' do
18
23
  expect(Book.left_join(:category).to_sql).to eq(
19
24
  "SELECT \"books\".* FROM \"books\" LEFT OUTER JOIN \"categories\" ON "\
20
- "\"books\".\"category_id\" = \"categories\".\"id\"")
25
+ "\"categories\".\"id\" = \"books\".\"category_id\"")
21
26
  end
22
27
 
23
28
  it 'works with nested associations' do
24
29
  expect(Category.left_join(books: :author).to_sql).to eq(
25
30
  "SELECT \"categories\".* FROM \"categories\" "\
26
31
  "LEFT OUTER JOIN \"books\" ON "\
27
- "\"categories\".\"id\" = \"books\".\"category_id\" "\
32
+ "\"books\".\"category_id\" = \"categories\".\"id\" "\
28
33
  "LEFT OUTER JOIN \"authors\" ON "\
29
- "\"books\".\"author_id\" = \"authors\".\"id\"")
30
- end
31
-
32
- it 'parses single argument to nodes' do
33
- expect(LeftJoin.parse_to_nodes(:category, Book)).to eq [
34
- Book.reflect_on_association(:category)]
35
- end
36
-
37
- it 'parses array argument to nodes' do
38
- expect(LeftJoin.parse_to_nodes([:category, :author], Book)).to eq [
39
- Book.reflect_on_association(:category),
40
- Book.reflect_on_association(:author)
41
- ]
34
+ "\"authors\".\"id\" = \"books\".\"author_id\"")
42
35
  end
43
36
 
44
- it 'parses hash argument to nodes' do
45
- expect(LeftJoin.parse_to_nodes({ books: :author }, Category)).to eq [
46
- Category.reflect_on_association(:books),
47
- Book.reflect_on_association(:author)
48
- ]
37
+ it 'works with polymorphic associations' do
38
+ expect(Book.left_join(:tags).to_sql).to eq(
39
+ "SELECT \"books\".* FROM \"books\" LEFT OUTER JOIN \"tags\" ON "\
40
+ "\"tags\".\"taggable_id\" = \"books\".\"id\" AND "\
41
+ "\"tags\".\"taggable_type\" = 'Book'")
49
42
  end
50
43
  end
data/spec/spec_helper.rb CHANGED
@@ -43,6 +43,11 @@ RSpec.configure do |config|
43
43
  create_table :categories do |t|
44
44
  t.string :name
45
45
  end
46
+
47
+ create_table :tags do |t|
48
+ t.string :name
49
+ t.belongs_to :taggable, polymorphic: true
50
+ end
46
51
  end
47
52
  end
48
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: left_join
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Aguir Selzlein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.0.1
61
+ version: 2.1.0
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.0.1
68
+ version: 2.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -127,7 +127,6 @@ files:
127
127
  - left_join.gemspec
128
128
  - lib/left_join.rb
129
129
  - lib/left_join/adapters/active_record_adapter.rb
130
- - lib/left_join/node.rb
131
130
  - spec/left_join_spec.rb
132
131
  - spec/spec_helper.rb
133
132
  homepage: http://github.com/nerde/left_join
@@ -150,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
149
  version: '0'
151
150
  requirements: []
152
151
  rubyforge_project:
153
- rubygems_version: 2.4.5.1
152
+ rubygems_version: 2.5.1
154
153
  signing_key:
155
154
  specification_version: 4
156
155
  summary: LEFT JOIN with ActiveRecord
@@ -1 +0,0 @@
1
- LeftJoin::Node = Struct.new(:key, :context)