Class: Most::DI::Proxy

Inherits:
Object show all
Defined in:
lib/most/di/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delegate, interfaces = {}) ⇒ Proxy



29
30
31
32
# File 'lib/most/di/proxy.rb', line 29

def initialize(delegate, interfaces = {})
  @delegate   = delegate
  @interfaces = interfaces
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/most/di/proxy.rb', line 35

def method_missing(name, *args, &block)
  result = nil

  begin
    interface = @interfaces[name.intern()]
    unless interface.nil?
      args << block if block_given?
      result = interface.call(@delegate, *args)
    else
      result = @delegate.send(name, *args, &block)
    end
  rescue Exception => e
    raise(e, "delegate - #{@delegate.class}, method - #{name} #{args}")
  end

  result
end

Instance Attribute Details

#delegateObject (readonly)

Returns the value of attribute delegate.



27
28
29
# File 'lib/most/di/proxy.rb', line 27

def delegate
  @delegate
end

#interfacesObject (readonly)

Returns the value of attribute interfaces.



27
28
29
# File 'lib/most/di/proxy.rb', line 27

def interfaces
  @interfaces
end