Class: Aspector::Advice
- Inherits:
-
Object
- Object
- Aspector::Advice
- Defined in:
- lib/aspector/advice.rb
Constant Summary collapse
- BEFORE =
1
- AFTER =
2
- AROUND =
3
- RAW =
4
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.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #after? ⇒ Boolean
- #around? ⇒ Boolean
- #before? ⇒ Boolean
-
#initialize(parent, type, method_matcher, with_method, options = {}, &block) ⇒ Advice
constructor
A new instance of Advice.
- #match?(method, context = nil) ⇒ Boolean
- #name ⇒ Object
- #raw? ⇒ Boolean
- #to_s ⇒ Object
- #type_name ⇒ 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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/aspector/advice.rb', line 12 def initialize parent, type, method_matcher, with_method, = {}, &block @parent = parent @type = type @method_matcher = method_matcher if with_method.is_a? Symbol @with_method = with_method else @advice_code = with_method end @options = @advice_block = block end |
Instance Attribute Details
#advice_block ⇒ Object (readonly)
Returns the value of attribute advice_block.
9 10 11 |
# File 'lib/aspector/advice.rb', line 9 def advice_block @advice_block end |
#advice_code ⇒ Object (readonly)
Returns the value of attribute advice_code.
9 10 11 |
# File 'lib/aspector/advice.rb', line 9 def advice_code @advice_code end |
#index ⇒ Object
Returns the value of attribute index.
10 11 12 |
# File 'lib/aspector/advice.rb', line 10 def index @index end |
#method_matcher ⇒ Object (readonly)
Returns the value of attribute method_matcher.
9 10 11 |
# File 'lib/aspector/advice.rb', line 9 def method_matcher @method_matcher end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/aspector/advice.rb', line 9 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/aspector/advice.rb', line 9 def type @type end |
Instance Method Details
#match?(method, context = nil) ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspector/advice.rb', line 37 def match? method, context = nil return if method == with_method return unless @method_matcher.match?(method, context) return true unless @options[:except] @except ||= MethodMatcher.new(@options[:except]) not @except.match?(method) end |
#name ⇒ Object
27 28 29 |
# File 'lib/aspector/advice.rb', line 27 def name @options[:name] || "advice #{index}" end |
#to_s ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/aspector/advice.rb', line 78 def to_s s = "#{name}: " s << type_name 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 |
#type_name ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/aspector/advice.rb', line 64 def type_name case @type when BEFORE then @options[:skip_if_false] ? "BEFORE_FILTER" : "BEFORE" when AFTER then "AFTER" when AROUND then "AROUND" when RAW then "RAW" else "UNKNOWN?!" end end |
#use_deferred_logic?(logic) ⇒ Boolean
74 75 76 |
# File 'lib/aspector/advice.rb', line 74 def use_deferred_logic? logic method_matcher.use_deferred_logic? logic end |
#with_method ⇒ Object
31 32 33 34 35 |
# File 'lib/aspector/advice.rb', line 31 def with_method unless @advice_code @with_method ||= "aop_#{hash.abs}" end end |