scopiform 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scopiform/scope_context.rb +6 -1
- data/lib/scopiform/utilities.rb +4 -1
- data/lib/scopiform/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf263f19bfbf29c2ce932d57306b0c4c0da85307b79a9f2df059fbe05a04a2b1
|
4
|
+
data.tar.gz: '0261898e3563b6ffeb8f5b3ae7e070e350929f8be178956e8fe5518ceaa8bd05'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4a0b35d5023ac441e99b5b82bfefc79c5e2aa74f36d1464ccc659f1c4be2099eb3a45571fdb567b19835bacf78f148860f55ff56a455032df63a26bed269805
|
7
|
+
data.tar.gz: 973ecc6033a2461c5b6b111ed506ff6fdb291318e7348d4c8a17be8e9d86a5dec6dca2e2b620452024d73070a002e7813fdcb1a8c55ecac5dbc2df8732ffdc83
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Scopiform
|
2
2
|
class ScopeContext
|
3
|
-
attr_accessor :association, :arel_table, :association_arel_table, :joins, :ancestors, :scopes
|
3
|
+
attr_accessor :association, :arel_table, :association_arel_table, :joins, :ancestors, :scopes, :has_manys
|
4
4
|
|
5
5
|
def self.from(ctx)
|
6
6
|
created = new
|
@@ -20,6 +20,7 @@ module Scopiform
|
|
20
20
|
@joins = []
|
21
21
|
@ancestors = []
|
22
22
|
@scopes = []
|
23
|
+
@has_manys = []
|
23
24
|
end
|
24
25
|
|
25
26
|
def set(arel_table)
|
@@ -35,6 +36,10 @@ module Scopiform
|
|
35
36
|
self.association = association.through_reflection
|
36
37
|
end
|
37
38
|
|
39
|
+
unless association.has_one? || association.belongs_to?
|
40
|
+
has_manys << association.name
|
41
|
+
end
|
42
|
+
|
38
43
|
ancestors << association.name.to_s.pluralize
|
39
44
|
self.association_arel_table = association.klass.arel_table.alias(alias_name)
|
40
45
|
|
data/lib/scopiform/utilities.rb
CHANGED
@@ -17,10 +17,13 @@ module Scopiform
|
|
17
17
|
|
18
18
|
ctx.association = association
|
19
19
|
ctx.build_joins
|
20
|
+
has_manys = ctx.has_manys.present?
|
20
21
|
|
21
22
|
applied = ctx.association.klass.send(method, value, ctx: ScopeContext.from(ctx).set(ctx.association_arel_table))
|
22
23
|
|
23
|
-
if is_root
|
24
|
+
if is_root && !has_manys
|
25
|
+
ctx.scopes.reduce(active_record.joins(ctx.joins).merge(applied)) { |chain, scope| chain.merge(scope) }
|
26
|
+
elsif is_root && has_manys
|
24
27
|
ctx.scopes.reduce(active_record.distinct.joins(ctx.joins).merge(applied)) { |chain, scope| chain.merge(scope) }
|
25
28
|
else
|
26
29
|
ctx.scopes.reduce(active_record.all.merge(applied)) { |chain, scope| chain.merge(scope) }
|
data/lib/scopiform/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scopiform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jayce.pulsipher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -123,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
|
127
|
-
rubygems_version: 2.7.7
|
126
|
+
rubygems_version: 3.1.2
|
128
127
|
signing_key:
|
129
128
|
specification_version: 4
|
130
129
|
summary: Generate scope methods to ActiveRecord classes based on columns and associations
|