Class: Spank::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/spank/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(target, interceptor_chain = InterceptorChain.new) ⇒ Proxy

Returns a new instance of Proxy.



3
4
5
6
# File 'lib/spank/proxy.rb', line 3

def initialize(target, interceptor_chain = InterceptorChain.new)
  @target = target
  @interceptor_chain = interceptor_chain
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



20
21
22
23
24
25
26
# File 'lib/spank/proxy.rb', line 20

def method_missing(method, *args, &block)
  if block
    @target.public_send(method, *args, block)
  else
    @target.public_send(method, *args)
  end
end

Instance Method Details

#add_interceptor(method, interceptor) ⇒ Object



8
9
10
11
12
# File 'lib/spank/proxy.rb', line 8

def add_interceptor(method, interceptor)
  @interceptor_chain.push(interceptor)
  self.extend(create_module_for(method))
  self
end