Class: Putter::Follower

Inherits:
BasicObject
Includes:
MethodCreator
Defined in:
lib/putter/follower.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MethodCreator

#add_putter_method_to_proxy

Constructor Details

#initialize(obj, options = {}) ⇒ Follower

Returns a new instance of Follower.



7
8
9
10
11
12
13
14
15
16
# File 'lib/putter/follower.rb', line 7

def initialize(obj, options={})
  @object = obj
  @proxy = MethodProxy.new
  begin
    @object.singleton_class.send(:prepend, proxy)
  rescue ::NoMethodError
    ::Kernel.raise ::Putter::BasicObjectError
  end
  @data = FollowerData.new(@object, @proxy, options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/putter/follower.rb', line 18

def method_missing(method, *args, &blk)
  if @data.add_method?(method)
    add_method(method)
  end

  if blk
    @object.send(method, *args, &blk)
  else
    @object.send(method, *args)
  end
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/putter/follower.rb', line 5

def object
  @object
end

#proxyObject (readonly)

Returns the value of attribute proxy.



5
6
7
# File 'lib/putter/follower.rb', line 5

def proxy
  @proxy
end

Instance Method Details

#add_method(method) ⇒ Object



30
31
32
33
34
# File 'lib/putter/follower.rb', line 30

def add_method(method)
  proxy_method_data = ProxyMethodData.new(label: @data.label, method: method)

  add_putter_method_to_proxy(@proxy, proxy_method_data)
end