Class: EDango::DI::Proxy

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

Defined Under Namespace

Classes: ProxyError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Proxy.



31
32
33
34
# File 'lib/edango/di/proxy.rb', line 31

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)



42
43
44
45
46
47
48
49
50
# File 'lib/edango/di/proxy.rb', line 42

def method_missing(name, *args, &block)
  interface = @interfaces[name.intern()]

  unless interface.nil?
    interface.call(@delegate, *args, &block)
  else
    @delegate.send(name, *args, &block)
  end
end

Instance Attribute Details

#delegateObject (readonly)

Returns the value of attribute delegate.



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

def delegate
  @delegate
end

#interfacesObject (readonly)

Returns the value of attribute interfaces.



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

def interfaces
  @interfaces
end

Instance Method Details

#respond_to?(symbol, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/edango/di/proxy.rb', line 36

def respond_to?(symbol, include_private=false)
  @delegate.respond_to?(symbol, include_private) ||
  @interfaces.has_key?(symbol)
end