Top Level Namespace
Defined Under Namespace
Modules: Kernel Classes: Aspect, Class, Cut, Joinpoint, Object, Symbol, Target
Instance Method Summary collapse
Instance Method Details
#cross_cut(klass) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/cuts/aop.rb', line 95 def cross_cut(klass) Cut.new(klass) do define_method :__base__ do klass end def advices @advices ||= {} end def self.extended(obj) base = obj.class #__base__ # use string for 1.9-, and symbol for 1.9+ methods = obj.methods + obj.public_methods + obj.protected_methods + obj.private_methods - [:advices, 'advices'] methods.uniq.each do |sym| #meth = obj.method(sym) define_method(sym) do |*args, &blk| jp = Joinpoint.new(self, base, sym, *args) #, &blk) # calculate advices on first use. unless advices[sym] advices[sym] = [] base.aspects.each do |aspect| aspect.points.each do |advice, matches| matches.each do |match| if jp === match advices[sym] << [aspect, advice] end end end end end if advices[sym].empty? super(*args, &blk) else target = jp #Target.new(self, sym, *args, &blk) # Target == JoinPoint ? advices[sym].each do |(aspect, advice)| target = Target.new(aspect, advice, target) end target.call #super end end #define_method end #methods end #def end end |