Class: Forwarder::Meta

Inherits:
Object
  • Object
show all
Defined in:
lib/forwarder/meta.rb

Overview

I am the workerbee defining the methods and stuff

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



5
6
7
# File 'lib/forwarder/meta.rb', line 5

def arguments
  @arguments
end

#forwardeeObject (readonly)

Returns the value of attribute forwardee.



5
6
7
# File 'lib/forwarder/meta.rb', line 5

def forwardee
  @forwardee
end

Instance Method Details

#forwardObject

TODO: Break AOP out of this so that we do not check @ runtime



8
9
10
11
12
13
14
15
16
# File 'lib/forwarder/meta.rb', line 8

def forward
  if arguments.before_with_block?
    forward_with_before_with_block
  elsif arguments.aop?
    forward_with_aop
  else
    forward_without_aop
  end
end

#forward_chainObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/forwarder/meta.rb', line 18

def forward_chain
  a = arguments
  sr = symbolic_receiver
  forwardee.module_eval do
    define_method a.message do |*args, &blk|
      if a.before_with_block?
        args = Array(a.before.(*args,&blk)) if a.before_with_block?
        blk = args.pop
      elsif a.before?
        args = instance_exec( *args, &a.before )
      end

      tgt = a.target.inject( self ){ |r, sym| sr.( r, sym ) }
      tgt.send( a.translation( a.message ), *a.complete_args(*args), &a.lambda( blk ) ).tap do | result |
          break a.after.( result ) if a.after?
        end
        #.send( a.translation( a.message ), *a.complete_args(*args), &a.lambda( blk ) ) 
    end
  end
end

#forward_objectObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/forwarder/meta.rb', line 39

def forward_object
  a = arguments
  forwardee.module_eval do
    define_method a.message do |*args, &blk|
      args = instance_exec( *args, &a.before ) if a.before?

      a.object_target( self )
        .send( a.translation( a.message ), *a.complete_args(*args), &a.lambda( blk ) ).tap do | result |
          break instance_exec( result, &a.after ) if a.after?
        end
    end
  end
  
end