module Lab42::AOP::Before
Public Instance Methods
with_block(rcv, tgts, **kwds, &blk)
click to toggle source
# File lib/lab42/aop/before.rb, line 4 def with_block rcv, tgts, **kwds, &blk concerns = CrossConcern.get_methods rcv, Array( tgts ), **kwds concerns.each do | tgt_concern | _define_block_before tgt_concern, blk end end
with_methods(rcv, tgts, aops, **kwds)
click to toggle source
# File lib/lab42/aop/before.rb, line 11 def with_methods rcv, tgts, aops, **kwds # aops loop must be outer loop as _define_method_before will change # the result of CrossConcern.get_methods rcv, ... Array( aops ).each do | aop | concerns = CrossConcern.get_methods rcv, Array( tgts ), **kwds concerns.each do | tgt_concern | _define_method_before tgt_concern, aop end end end
Private Instance Methods
_define_block_before(tgt_concern, blk)
click to toggle source
# File lib/lab42/aop/before.rb, line 23 def _define_block_before tgt_concern, blk unique_name = "__#{tgt_concern.name}_#{SecureRandom.uuid.gsub('-','_')}" tgt_concern.cls.send :define_method, unique_name, &blk tgt_concern.cls.send :define_method, tgt_concern.name do |*a, &b| send unique_name, *a, &b tgt_concern.mthd.bind( self ).( *a, &b ) end end
_define_method_before(tgt_concern, aop)
click to toggle source
# File lib/lab42/aop/before.rb, line 33 def _define_method_before tgt_concern, aop tgt_concern.cls.send :define_method, tgt_concern.name do |*a, &b| send( aop, *a, &b ) tgt_concern.mthd.bind( self ).( *a, &b ) end end