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) : superend
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.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aquarium/aspects/advice.rb', line 47 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(" attr_accessor(:\#{key})\n EOF\n end\nend\n", __FILE__, __LINE__) |
Instance Method Details
#call(jp) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/aquarium/aspects/advice.rb', line 68 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.
60 61 62 63 64 65 66 |
# File 'lib/aquarium/aspects/advice.rb', line 60 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
85 86 87 88 89 90 91 |
# File 'lib/aquarium/aspects/advice.rb', line 85 def each node = self while node.nil? == false yield node node = node.next_node end end |
#empty? ⇒ Boolean
103 104 105 |
# File 'lib/aquarium/aspects/advice.rb', line 103 def empty? next_node.nil? end |
#invoke_original_join_point(current_jp) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/aquarium/aspects/advice.rb', line 76 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
93 94 95 96 97 |
# File 'lib/aquarium/aspects/advice.rb', line 93 def last last_node = nil each { |node| last_node = node unless node.nil? } last_node end |
#size ⇒ Object
99 100 101 |
# File 'lib/aquarium/aspects/advice.rb', line 99 def size inject(0) {|memo, node| memo += 1} end |