Class: Aquarium::Aspects::AdviceChainNode

Inherits:
Object
  • Object
show all
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!

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

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 options = {}
  # assign :next_node and :static_join_point so the attributes are always created
  options[:next_node] ||= nil  
  options[:static_join_point] ||= nil
  options.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

#eachObject

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

Returns:

  • (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

#lastObject



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

#sizeObject



99
100
101
# File 'lib/aquarium/aspects/advice.rb', line 99

def size
  inject(0) {|memo, node| memo += 1}
end