Class: Aquarium::Aspects::AdviceChainNode
- Includes:
- Enumerable
- Defined in:
- lib/aquarium/aspects/advice.rb
Overview
Supports Enumerable, but not the sorting methods, as this class is a linked list structure. This is of limited usefulness, because you wouldn't use an iterator to invoke the procs in the chain, because each proc will invoke the next node arbitrarily or possibly not at all in the case of around advice!
Direct Known Subclasses
AfterAdviceChainNode, AfterRaisingAdviceChainNode, AfterReturningAdviceChainNode, AroundAdviceChainNode, BeforeAdviceChainNode, NoAdviceChainNode
Constant Summary collapse
- NIL_OBJECT =
TODO: remove this method, which causes run-away recursions in R1.9.1 def inspect &block block ? yield(self) : super end
Aquarium::Utils::NilObject.new
Instance Method Summary collapse
- #call(jp) ⇒ Object
-
#call_advice(jp) ⇒ Object
Bug #19262 workaround: need to only pass jp argument if arity is 1.
-
#each ⇒ Object
Supports Enumerable.
- #empty? ⇒ Boolean
-
#initialize(options = {}) ⇒ AdviceChainNode
constructor
A new instance of AdviceChainNode.
- #invoke_original_join_point(current_jp) ⇒ Object
- #last ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AdviceChainNode
Returns a new instance of AdviceChainNode.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/aquarium/aspects/advice.rb', line 49 def initialize = {} # assign :next_node and :static_join_point so the attributes are always created [:next_node] ||= nil [:static_join_point] ||= nil .each do |key, value| instance_variable_set "@#{key}".intern, value (class << self; self; end).class_eval(<<-EOF, __FILE__, __LINE__) attr_accessor(:#{key}) EOF end end |
Instance Method Details
#call(jp) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/aquarium/aspects/advice.rb', line 70 def call jp begin advice_wrapper jp rescue Exception => e handle_call_rescue e, "", jp end end |
#call_advice(jp) ⇒ Object
Bug #19262 workaround: need to only pass jp argument if arity is 1.
62 63 64 65 66 67 68 |
# File 'lib/aquarium/aspects/advice.rb', line 62 def call_advice jp if advice.arity == 1 advice.call jp else advice.call jp, jp.context.advised_object, *jp.context.parameters end end |
#each ⇒ Object
Supports Enumerable
87 88 89 90 91 92 93 |
# File 'lib/aquarium/aspects/advice.rb', line 87 def each node = self while node.nil? == false yield node node = node.next_node end end |
#empty? ⇒ Boolean
105 106 107 |
# File 'lib/aquarium/aspects/advice.rb', line 105 def empty? next_node.nil? end |
#invoke_original_join_point(current_jp) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/aquarium/aspects/advice.rb', line 78 def invoke_original_join_point current_jp begin last.advice_wrapper current_jp rescue Exception => e handle_call_rescue e, "While executing the original join_point: ", current_jp end end |
#last ⇒ Object
95 96 97 98 99 |
# File 'lib/aquarium/aspects/advice.rb', line 95 def last last_node = nil each { |node| last_node = node unless node.nil? } last_node end |
#size ⇒ Object
101 102 103 |
# File 'lib/aquarium/aspects/advice.rb', line 101 def size inject(0) {|memo, node| memo += 1} end |