class AspectR::Aspect
Constants
- POST
- PRE
Public Class Methods
dispatch?()
click to toggle source
# File lib/aspectr.rb, line 69 def Aspect.dispatch? @@__aop_dispatch end
new(never_wrap = "^$ ")
click to toggle source
# File lib/aspectr.rb, line 29 def initialize(never_wrap = "^$ ") @never_wrap = /^__|^send$|^object_id$|^class$|#{never_wrap}/ end
Public Instance Methods
add_advice(target, joinpoint, method, advice)
click to toggle source
# File lib/aspectr.rb, line 55 def add_advice(target, joinpoint, method, advice) prepare(target) if advice target.__aop_install_dispatcher(method) target.__aop_add_advice(joinpoint, method, self, advice) end end
disable_advice_dispatching() { || ... }
click to toggle source
# File lib/aspectr.rb, line 73 def disable_advice_dispatching begin @@__aop_dispatch = false yield ensure @@__aop_dispatch = true end end
get_methods(target, args)
click to toggle source
# File lib/aspectr.rb, line 82 def get_methods(target, args) if args.first.is_a? Regexp if target.kind_of?(Class) methods = target.instance_methods(true) else methods = target.methods end methods = methods.grep(args.first).collect{|e| e.intern} else methods = args end methods.select {|method| wrappable?(method)} end
prepare(target)
click to toggle source
# File lib/aspectr.rb, line 100 def prepare(target) unless target.respond_to?("__aop_init") target.extend AspectSupport target.__aop_init end end
remove_advice(target, joinpoint, method, advice)
click to toggle source
# File lib/aspectr.rb, line 63 def remove_advice(target, joinpoint, method, advice) target.__aop_remove_advice(joinpoint, method, self, advice) if advice end
unwrap(target, pre, post, *args)
click to toggle source
# File lib/aspectr.rb, line 40 def unwrap(target, pre, post, *args) get_methods(target, args).each do |method_to_unwrap| remove_advice(target, PRE, method_to_unwrap, pre) remove_advice(target, POST, method_to_unwrap , post) end end
wrap(target, pre, post, *args)
click to toggle source
# File lib/aspectr.rb, line 33 def wrap(target, pre, post, *args) get_methods(target, args).each do |method_to_wrap| add_advice(target, PRE, method_to_wrap, pre) add_advice(target, POST, method_to_wrap, post) end end
wrap_with_code(target, preCode, postCode, *args)
click to toggle source
Sticky and faster wrap (can't be unwrapped).
# File lib/aspectr.rb, line 48 def wrap_with_code(target, preCode, postCode, *args) prepare(target) get_methods(target, args).each do |method_to_wrap| target.__aop_wrap_with_code(method_to_wrap, preCode, postCode) end end
wrappable?(method)
click to toggle source
# File lib/aspectr.rb, line 96 def wrappable?(method) method.to_s !~ @never_wrap end