polymorphic_join 0.2.3 → 0.2.4

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
  SHA256:
3
- metadata.gz: c613dd44e44c5926f53a7563876aa768be0a1c4ed93d7a5b6d466f288d225c14
4
- data.tar.gz: b11dca1df7bbe4e17d8017ba7cb929151bd1373e95ab6f11fcb109a33bd48938
3
+ metadata.gz: 5fd251d3029cdb8c257de506b471e1f54ee561079c9f0acf771012f8afb55e6d
4
+ data.tar.gz: 06a5c1834878040bdd5cde452bfbf6b6888df68f345293cfecc0a1dab4387d1a
5
5
  SHA512:
6
- metadata.gz: 572ccc4a2074c1a8ec8a46cfe9f286516e4ae412f31f1ed0376ad746dc051d87f0cfbb3d5a9303ca962cada9129da83fd84aa79870c948c7190cd27a7e4aade8
7
- data.tar.gz: bd8efc9ef21a1d92919069ed39fa39f3b476258d46b49bdf57bb3b98bd623b10e6c2baed676bb2d1306b033c984a7d48f1733be584b06551d6fe97a9711aa63d
6
+ metadata.gz: 0ce57792b3426e1aad896ab9158fa421b3bcee927ad98be31f7174d496cf331092f702ff5acad7a38e1fcb29a30ccade1b0fb20e9d7b6bc94461ee392e6f6de3
7
+ data.tar.gz: 2e1c899de63404ba46ec050e7efae4ed1b8c821eaa6a775f5c9dfa4907448fde9713160f1bed75a855059b4db87d58399a933a6e7c4a43bfbf8ea5026b09f685
@@ -80,16 +80,19 @@ module PolymorphicJoin
80
80
 
81
81
  protected
82
82
 
83
+ def build_union(left, right)
84
+ if right.length > 1
85
+ Arel::Nodes::Union.new(left, build_union(right[0], right[1..-1]))
86
+ else
87
+ Arel::Nodes::Union.new(left, right[0])
88
+ end
89
+ end
90
+
83
91
  def polymorphic_union_scope(type, refs, *scopes)
84
92
  union = scopes[0]
85
93
  t2 = arel_table
86
94
 
87
- if scopes.length > 1
88
- (1..(scopes.length - 1)).each do |i|
89
- union = union.union(scopes[i])
90
- end
91
- end
92
-
95
+ union = build_union(scopes[0], scopes[1..-1]) if scopes.length > 1
93
96
  types = type.to_s.pluralize
94
97
  t1 = arel_table.create_table_alias(union, types)
95
98
  from(
@@ -1,3 +1,3 @@
1
1
  module PolymorphicJoin
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.2.4'.freeze
3
3
  end
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.3
4
+ version: 0.2.4
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-13 00:00:00.000000000 Z
11
+ date: 2019-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler