scopiform 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/scopiform/association_scopes.rb +2 -2
- data/lib/scopiform/core.rb +2 -0
- data/lib/scopiform/scope_context.rb +11 -4
- data/lib/scopiform/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60fdf69684da8b4a16efc5b52b69bcae18d30824b844fb57fdc3219780ed2894
|
4
|
+
data.tar.gz: fbc86f9e966127b7c64546adc46b805e1c78caaa6d8aa9c49acceaeea7120639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6165fbab6073d4ec637aed25cfb58d2f13ef7ecd590724b17374f47e9718850c62740655768f11f1e1b7f14a119a30eba863897c6189b620844e03b0c54fa0ee
|
7
|
+
data.tar.gz: 5730438bea472073e31a9f37d45ce3de8e066615e9dea0b0fa99af5bb955d5b3192cd068898c6367515d959d84354a202c90d405f5a08f488f8f07f342439aa7
|
@@ -23,9 +23,9 @@ module Scopiform
|
|
23
23
|
applied = ctx.association.klass.send(method, value, ctx: ScopeContext.from(ctx).set(ctx.association_arel_table))
|
24
24
|
|
25
25
|
if is_root
|
26
|
-
joins(ctx.joins).merge(applied)
|
26
|
+
ctx.scopes.reduce(joins(ctx.joins).merge(applied)) { |chain, scope| chain.merge(scope) }
|
27
27
|
else
|
28
|
-
all.merge(applied)
|
28
|
+
ctx.scopes.reduce(all.merge(applied)) { |chain, scope| chain.merge(scope) }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
data/lib/scopiform/core.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Scopiform
|
2
2
|
class ScopeContext
|
3
|
-
attr_accessor :association, :arel_table, :association_arel_table, :joins, :ancestors
|
3
|
+
attr_accessor :association, :arel_table, :association_arel_table, :joins, :ancestors, :scopes
|
4
4
|
|
5
5
|
def self.from(ctx)
|
6
6
|
created = new
|
@@ -19,6 +19,7 @@ module Scopiform
|
|
19
19
|
def initialize
|
20
20
|
@joins = []
|
21
21
|
@ancestors = []
|
22
|
+
@scopes = []
|
22
23
|
end
|
23
24
|
|
24
25
|
def set(arel_table)
|
@@ -34,18 +35,24 @@ module Scopiform
|
|
34
35
|
self.association = association.through_reflection
|
35
36
|
end
|
36
37
|
|
37
|
-
ancestors << association.name
|
38
|
+
ancestors << association.name.to_s.pluralize
|
38
39
|
self.association_arel_table = association.klass.arel_table.alias(alias_name)
|
39
40
|
|
40
41
|
joins << create_join
|
41
42
|
|
43
|
+
if association.scope.present? && association.scope.arity.zero?
|
44
|
+
association.klass.scopiform_ctx = ScopeContext.from(self).set(association_arel_table)
|
45
|
+
scopes << association.klass.instance_exec(&association.scope)
|
46
|
+
association.klass.scopiform_ctx = nil
|
47
|
+
end
|
48
|
+
|
42
49
|
break if source_reflection_name.blank?
|
43
50
|
|
44
|
-
self.association = association.klass.
|
51
|
+
self.association = association.klass.reflect_on_association(source_reflection_name)
|
45
52
|
self.arel_table = association_arel_table
|
46
53
|
end
|
47
54
|
|
48
|
-
|
55
|
+
joins
|
49
56
|
end
|
50
57
|
|
51
58
|
def alias_name
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jayce.pulsipher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|