polymorphic_join 0.2.2 → 0.2.3

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: b2e3c19213a3b9fbe21bfa6d1ea920f31c9f5def
4
- data.tar.gz: 5bf97916ff403fc3a719da1711efdce1bd2adc1d
2
+ SHA256:
3
+ metadata.gz: c613dd44e44c5926f53a7563876aa768be0a1c4ed93d7a5b6d466f288d225c14
4
+ data.tar.gz: b11dca1df7bbe4e17d8017ba7cb929151bd1373e95ab6f11fcb109a33bd48938
5
5
  SHA512:
6
- metadata.gz: dd699d99211940f5f9fc54e350b33b69bd98a60ea880a84034717dcd24b2634327d8c7f5c7113d20f995958f4c91633187f0c6ad2ede6d4531d7a0d721d931ce
7
- data.tar.gz: 2be3693618f439c047a23f578c205d21becd4f2cc2bcc694a263a428cffb7ab0780bdae58a8d641df022fe01fc115187f6c4dcb49adf59d18e59fe2c3b232833
6
+ metadata.gz: 572ccc4a2074c1a8ec8a46cfe9f286516e4ae412f31f1ed0376ad746dc051d87f0cfbb3d5a9303ca962cada9129da83fd84aa79870c948c7190cd27a7e4aade8
7
+ data.tar.gz: bd8efc9ef21a1d92919069ed39fa39f3b476258d46b49bdf57bb3b98bd623b10e6c2baed676bb2d1306b033c984a7d48f1733be584b06551d6fe97a9711aa63d
@@ -1,3 +1,3 @@
1
1
  module PolymorphicJoin
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- # rubocop:disable MethodLength, AbcSize
1
+ # rubocop:disable MethodLength, AbcSize, ModuleLength
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'polymorphic_join/version'
@@ -73,12 +73,14 @@ module PolymorphicJoin
73
73
  )
74
74
  end
75
75
 
76
- polymorphic_union_scope(types, *joins_statements)
76
+ polymorphic_union_scope(
77
+ type, polymorphic[:refs], *joins_statements
78
+ )
77
79
  end
78
80
 
79
81
  protected
80
82
 
81
- def polymorphic_union_scope(types, *scopes)
83
+ def polymorphic_union_scope(type, refs, *scopes)
82
84
  union = scopes[0]
83
85
  t2 = arel_table
84
86
 
@@ -88,8 +90,20 @@ module PolymorphicJoin
88
90
  end
89
91
  end
90
92
 
93
+ types = type.to_s.pluralize
91
94
  t1 = arel_table.create_table_alias(union, types)
92
- from(t2.create_join(t1, t2.create_on(t1[:id].eq(t2[:id]))))
95
+ from(
96
+ t2.create_join(
97
+ t1,
98
+ t2.create_on(
99
+ t1[:id].eq(t2["#{type}_id".to_sym]).and(
100
+ t2["#{type}_type"].in(
101
+ refs.collect { |x| x.to_s.singularize.classify }
102
+ )
103
+ )
104
+ )
105
+ )
106
+ ).distinct
93
107
  end
94
108
 
95
109
  def retrieve_all_polymorphic_types(type)
@@ -104,7 +118,6 @@ module PolymorphicJoin
104
118
  poly_refs << (ref.is_a?(Symbol) ? ref : ref.keys.first)
105
119
  end
106
120
 
107
- puts refs.inspect
108
121
  {
109
122
  refs: poly_refs,
110
123
  map_columns: refs.each_with_object({}) do |el, hash|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polymorphic_join
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Huynh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-05 00:00:00.000000000 Z
11
+ date: 2019-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.6.13
79
+ rubygems_version: 3.0.3
81
80
  signing_key:
82
81
  specification_version: 4
83
82
  summary: This gem is used to do polymorphic join