Class: Aspector::Advice
- Inherits:
-
Object
- Object
- Aspector::Advice
- Defined in:
- lib/aspector/advice.rb
Overview
A single aspect advice representation
Constant Summary collapse
- TYPES =
All available advices types that we support
%i( before before_filter after around raw )
Instance Attribute Summary collapse
-
#advice_block ⇒ Object
readonly
Returns the value of attribute advice_block.
-
#advice_code ⇒ Object
readonly
Returns the value of attribute advice_code.
-
#index ⇒ Object
Returns the value of attribute index.
-
#method_matcher ⇒ Object
readonly
Returns the value of attribute method_matcher.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(parent, type, method_matcher, with_method, options = {}, &block) ⇒ Advice
constructor
A new instance of Advice.
- #match?(method, context = nil) ⇒ Boolean
- #to_s ⇒ Object
- #use_deferred_logic?(logic) ⇒ Boolean
- #with_method ⇒ Object
Constructor Details
#initialize(parent, type, method_matcher, with_method, options = {}, &block) ⇒ Advice
Returns a new instance of Advice.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/aspector/advice.rb', line 29 def initialize(parent, type, method_matcher, with_method, = {}, &block) @type = type @parent = parent @options = @advice_block = block @method_matcher = method_matcher @name = @options[:name] || "advice_#{index}" if with_method.is_a? Symbol @with_method = with_method else @advice_code = with_method end end |
Instance Attribute Details
#advice_block ⇒ Object (readonly)
Returns the value of attribute advice_block.
26 27 28 |
# File 'lib/aspector/advice.rb', line 26 def advice_block @advice_block end |
#advice_code ⇒ Object (readonly)
Returns the value of attribute advice_code.
26 27 28 |
# File 'lib/aspector/advice.rb', line 26 def advice_code @advice_code end |
#index ⇒ Object
Returns the value of attribute index.
27 28 29 |
# File 'lib/aspector/advice.rb', line 27 def index @index end |
#method_matcher ⇒ Object (readonly)
Returns the value of attribute method_matcher.
26 27 28 |
# File 'lib/aspector/advice.rb', line 26 def method_matcher @method_matcher end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/aspector/advice.rb', line 26 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/aspector/advice.rb', line 26 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
26 27 28 |
# File 'lib/aspector/advice.rb', line 26 def type @type end |
Instance Method Details
#match?(method, context = nil) ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/aspector/advice.rb', line 50 def match?(method, context = nil) return false if method == with_method return false unless @method_matcher.match?(method, context) return true unless @options[:except] @except ||= MethodMatcher.new(@options[:except]) !@except.match?(method) end |
#to_s ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/aspector/advice.rb', line 65 def to_s s = "#{name}: " s << type.to_s.upcase s << ' [' << @method_matcher.to_s << '] DO ' if @with_method s << @with_method.to_s else s << 'stuff in block' end s << ' WITH OPTIONS ' << @options.inspect s end |
#use_deferred_logic?(logic) ⇒ Boolean
61 62 63 |
# File 'lib/aspector/advice.rb', line 61 def use_deferred_logic?(logic) method_matcher.use_deferred_logic? logic end |
#with_method ⇒ Object
44 45 46 47 48 |
# File 'lib/aspector/advice.rb', line 44 def with_method return nil if @advice_code @with_method ||= "aop_#{hash.abs}" end |