Class: Slaver::ScopeProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/slaver/scope_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, config_name) ⇒ ScopeProxy

Returns a new instance of ScopeProxy.



5
6
7
8
# File 'lib/slaver/scope_proxy.rb', line 5

def initialize(klass, config_name)
  @klass = klass
  @config_name = config_name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/slaver/scope_proxy.rb', line 15

def method_missing(method, *args, &block)
  result = self
  ::ActiveRecord::Base.within(config_name) do
    result = klass.send(method, *args, &block)

    if result.is_a?(ActiveRecord::Relation)
      @klass = result
      return self
    end
  end

  result
end

Instance Attribute Details

#config_nameObject (readonly)

Returns the value of attribute config_name.



3
4
5
# File 'lib/slaver/scope_proxy.rb', line 3

def config_name
  @config_name
end

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/slaver/scope_proxy.rb', line 3

def klass
  @klass
end

Instance Method Details

#on(config_name) ⇒ Object



10
11
12
13
# File 'lib/slaver/scope_proxy.rb', line 10

def on(config_name)
  @config_name = config_name
  self
end