Class: Primer::Lazyness::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/primer/lazyness.rb

Instance Method Summary collapse

Constructor Details

#initialize(real_class, primary_key, load_method, arguments, block) ⇒ Proxy

Returns a new instance of Proxy.



28
29
30
31
32
33
34
# File 'lib/primer/lazyness.rb', line 28

def initialize(real_class, primary_key, load_method, arguments, block)
  @real_class  = real_class
  @primary_key = primary_key
  @load_method = load_method
  @arguments   = arguments
  @block       = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/primer/lazyness.rb', line 36

def method_missing(method_name, *args, &block)
  if @load_method.to_s == 'eager_method_missing'
    if method_name.to_s == @arguments.first.to_s.gsub(/^find_by_/, '')
      Watcher.log(self, method_name.to_sym, args, block, @arguments[1])
      return @arguments[1]
    else
      return __subject__.__send__(method_name, *args, &block)
    end
  end
  
  if method_name.to_s == @primary_key.to_s
    Watcher.log(self, method_name.to_sym, args, block, @arguments.first)
    return @arguments.first
  end
  
  __subject__.__send__(method_name, *args, &block)
end