class Aquarium::Aspects::AdviceChainNode

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!

Constants

NIL_OBJECT

TODO: remove this method, which causes run-away recursions in R1.9.1 def inspect &block

block ? yield(self) : super

end

Public Class Methods

new(options = {}) click to toggle source
   # File lib/aquarium/aspects/advice.rb
49       def initialize options = {}
50         # assign :next_node and :static_join_point so the attributes are always created
51         options[:next_node] ||= nil
52         options[:static_join_point] ||= nil
53         options.each do |key, value|
54           instance_variable_set "@#{key}".intern, value
55           (class << self; self; end).class_eval(<<-EOF, __FILE__, __LINE__)
56             attr_accessor(:#{key})
57           EOF
58         end
59       end

Public Instance Methods

call(jp) click to toggle source
   # File lib/aquarium/aspects/advice.rb
70 def call jp
71   begin
72     advice_wrapper jp
73   rescue Exception => e
74     handle_call_rescue e, "", jp
75   end
76 end
call_advice(jp) click to toggle source

Bug #19262 workaround: need to only pass jp argument if arity is 1.

   # File lib/aquarium/aspects/advice.rb
62 def call_advice jp
63   if advice.arity == 1
64     advice.call jp
65   else
66     advice.call jp, jp.context.advised_object, *jp.context.parameters
67   end
68 end
each() { |node| ... } click to toggle source

Supports Enumerable

   # File lib/aquarium/aspects/advice.rb
87 def each
88   node = self
89   while node.nil? == false
90     yield node
91     node = node.next_node
92   end
93 end
empty?() click to toggle source
    # File lib/aquarium/aspects/advice.rb
105 def empty?
106   next_node.nil?
107 end
invoke_original_join_point(current_jp) click to toggle source
   # File lib/aquarium/aspects/advice.rb
78 def invoke_original_join_point current_jp
79   begin
80     last.advice_wrapper current_jp
81   rescue Exception => e
82     handle_call_rescue e, "While executing the original join_point: ", current_jp
83   end
84 end
last() click to toggle source
   # File lib/aquarium/aspects/advice.rb
95 def last
96   last_node = nil
97   each { |node| last_node = node unless node.nil? }
98   last_node
99 end
size() click to toggle source
    # File lib/aquarium/aspects/advice.rb
101 def size
102   inject(0) {|memo, node| memo += 1}
103 end

Protected Instance Methods

handle_call_rescue(ex, error_message_prefix, jp) click to toggle source
    # File lib/aquarium/aspects/advice.rb
135 def handle_call_rescue ex, error_message_prefix, jp
136   if Aquarium::Aspects::Advice.debug_backtraces
137     class_or_instance_method_separater = jp.instance_method? ? "#" : "."
138     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}\": "
139 
140     # Don't prepend the same context message multiple times
141     if ex.message =~ /#{context_message}/
142       context_message = ""
143     end
144 
145     backtrace = ex.backtrace
146     e2 = ex.exception(context_message + ex.message + " (join_point = #{jp.inspect})")
147     e2.set_backtrace backtrace
148     raise e2
149   else
150     raise ex
151   end
152 end
reset_current_context(jp) click to toggle source
    # File lib/aquarium/aspects/advice.rb
129 def reset_current_context jp
130   return if advice.arity == 0
131   jp.context.advice_kind = @last_advice_kind
132   jp.context.current_advice_node = @last_advice_node
133 end
update_current_context(jp) click to toggle source
    # File lib/aquarium/aspects/advice.rb
122 def update_current_context jp
123   return if advice.arity == 0
124   @last_advice_kind = jp.context.advice_kind
125   @last_advice_node = jp.context.current_advice_node
126   jp.context.current_advice_node = self
127 end