Class: Aspector::Interception
- Inherits:
-
Object
- Object
- Aspector::Interception
- Defined in:
- lib/aspector/interception.rb
Instance Attribute Summary collapse
-
#aspect ⇒ Object
readonly
Returns the value of attribute aspect.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #advices ⇒ Object
- #apply ⇒ Object
- #apply_to_method(method, scope = nil) ⇒ Object
- #apply_to_methods ⇒ Object
- #disabled? ⇒ Boolean
-
#initialize(aspect, target, options) ⇒ Interception
constructor
A new instance of Interception.
- #logger ⇒ Object
Constructor Details
#initialize(aspect, target, options) ⇒ Interception
Returns a new instance of Interception.
7 8 9 10 11 12 |
# File 'lib/aspector/interception.rb', line 7 def initialize aspect, target, @aspect = aspect @target = target @options = @wrapped_methods = {} end |
Instance Attribute Details
#aspect ⇒ Object (readonly)
Returns the value of attribute aspect.
5 6 7 |
# File 'lib/aspector/interception.rb', line 5 def aspect @aspect end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/aspector/interception.rb', line 5 def @options end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
5 6 7 |
# File 'lib/aspector/interception.rb', line 5 def target @target end |
Instance Method Details
#advices ⇒ Object
18 19 20 |
# File 'lib/aspector/interception.rb', line 18 def advices @aspect.class.advices end |
#apply ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/aspector/interception.rb', line 26 def apply invoke_deferred_logics define_methods_for_advice_blocks add_to_instances unless @options[:existing_methods_only] apply_to_methods unless @options[:new_methods_only] add_method_hooks unless @options[:existing_methods_only] # TODO: clear deferred logic results if they are not used in any advice return end |
#apply_to_method(method, scope = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/aspector/interception.rb', line 68 def apply_to_method method, scope = nil filtered_advices = filter_advices advices, method return if filtered_advices.empty? logger.debug 'apply-to-method', method scope ||= if context.private_instance_methods.include?(method.to_sym) :private elsif context.protected_instance_methods.include?(method.to_sym) :protected else :public end recreate_method method, filtered_advices, scope end |
#apply_to_methods ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/aspector/interception.rb', line 36 def apply_to_methods return if advices.empty? # If method/methods option is set and all are String or Symbol, apply to those only, instead of # iterating through all methods methods = [@options[:method] || @options[:methods]] methods.compact! methods.flatten! if not methods.empty? and methods.all?{|method| method.is_a? String or method.is_a? Symbol } methods.each do |method| apply_to_method(method.to_s) end return end context.public_instance_methods.each do |method| apply_to_method(method.to_s, :public) end context.protected_instance_methods.each do |method| apply_to_method(method.to_s, :protected) end if @options[:private_methods] context.private_instance_methods.each do |method| apply_to_method(method.to_s, :private) end end end |
#disabled? ⇒ Boolean
14 15 16 |
# File 'lib/aspector/interception.rb', line 14 def disabled? @aspect.disabled? end |
#logger ⇒ Object
22 23 24 |
# File 'lib/aspector/interception.rb', line 22 def logger @logger ||= Logging.get_logger(self) end |