| Class | Aquarium::Aspects::AdviceChainNode |
| In: |
lib/aquarium/aspects/advice.rb
|
| Parent: | Object |
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!
| NIL_OBJECT | = | Aquarium::Utils::NilObject.new |
# File lib/aquarium/aspects/advice.rb, line 43
43: def initialize options = {}
44: # assign :next_node and :static_join_point so the attributes are always created
45: options[:next_node] ||= nil
46: options[:static_join_point] ||= nil
47: options.each do |key, value|
48: instance_variable_set "@#{key}".intern, value
49: (class << self; self; end).class_eval("attr_accessor(:\#{key})\n", __FILE__, __LINE__)
50: end
51: end
# File lib/aquarium/aspects/advice.rb, line 65
65: def call jp
66: begin
67: advice_wrapper jp
68: rescue Exception => e
69: handle_call_rescue e, "", jp
70: end
71: end
Bug 19262 workaround: need to only pass jp argument if arity is 1.
# File lib/aquarium/aspects/advice.rb, line 57
57: def call_advice jp
58: if advice.arity == 1
59: advice.call jp
60: else
61: advice.call jp, jp.context.advised_object, *jp.context.parameters
62: end
63: end
Supports Enumerable
# File lib/aquarium/aspects/advice.rb, line 82
82: def each
83: node = self
84: while node.nil? == false
85: yield node
86: node = node.next_node
87: end
88: end
# File lib/aquarium/aspects/advice.rb, line 104
104: def inspect &block
105: block ? yield(self) : super
106: end
# File lib/aquarium/aspects/advice.rb, line 73
73: def invoke_original_join_point current_jp
74: begin
75: last.advice_wrapper current_jp
76: rescue Exception => e
77: handle_call_rescue e, "While executing the original join_point: ", current_jp
78: end
79: end
# File lib/aquarium/aspects/advice.rb, line 90
90: def last
91: last_node = nil
92: each { |node| last_node = node unless node.nil? }
93: last_node
94: end
# File lib/aquarium/aspects/advice.rb, line 96
96: def size
97: inject(0) {|memo, node| memo += 1}
98: end
# File lib/aquarium/aspects/advice.rb, line 129
129: def handle_call_rescue ex, error_message_prefix, jp
130: class_or_instance_method_separater = jp.instance_method? ? "#" : "."
131: context_message = error_message_prefix + "Exception raised while executing \"#{jp.context.advice_kind}\" advice for \"#{jp.type_or_object.inspect}#{class_or_instance_method_separater}#{jp.method_name}\": "
132: backtrace = ex.backtrace
133: e2 = ex.exception(context_message + ex.message + " (join_point = #{jp.inspect})")
134: e2.set_backtrace backtrace
135: raise e2
136: end
# File lib/aquarium/aspects/advice.rb, line 123
123: def reset_current_context jp
124: return if advice.arity == 0
125: jp.context.advice_kind = @last_advice_kind
126: jp.context.current_advice_node = @last_advice_node
127: end