scopiform 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: bdd67fcd99f42ab665dd31c6fedebe66f490e28ccb03d5d9ad5bd68d6c074b04
4
- data.tar.gz: eb6622a1ca3489a78156e290020c36153ddd6008e9a97af05804b94b8cf4a2e4
3
+ metadata.gz: 60fdf69684da8b4a16efc5b52b69bcae18d30824b844fb57fdc3219780ed2894
4
+ data.tar.gz: fbc86f9e966127b7c64546adc46b805e1c78caaa6d8aa9c49acceaeea7120639
5
5
  SHA512:
6
- metadata.gz: ebbbc3f4ed13cddd576958a6b82f5bd2238cb8930ac242ed3dfaeca6bdd71f388c9eaa33912cf02acdfaf31f710737aab3bbcbf2a1654f25a199ad5443eb53d5
7
- data.tar.gz: 6ea5675e9a5a6d68a2221b4affd5887cd3a0b8a57c407515b693bb65ab0a49b0fde09d7a3c8a39bb1a14d22e074907ce417f92216a82e8b8aa188d269c8c4187
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
 
@@ -8,6 +8,8 @@ module Scopiform
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  module ClassMethods
11
+ attr_accessor :scopiform_ctx
12
+
11
13
  def auto_scopes
12
14
  @auto_scopes || []
13
15
  end
@@ -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.association(source_reflection_name)
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
- self
55
+ joins
49
56
  end
50
57
 
51
58
  def alias_name
@@ -1,3 +1,3 @@
1
1
  module Scopiform
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: scopiform
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
  - jayce.pulsipher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-02 00:00:00.000000000 Z
11
+ date: 2020-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord