Class: Aquarium::Aspects::JoinPoint::Context
- Defined in:
- lib/aquarium/aspects/join_point.rb
Overview
JoinPoint::Context
Encapsulates current runtime context information for a join point, such as the values of method parameters, a raised exception (for :after
or after_raising
advice), etc. Context objects are partly value objects. TODO Separate out the read-only part from the variable part. This might require an API change!
Constant Summary collapse
Instance Attribute Summary collapse
-
#advice_kind ⇒ Object
Returns the value of attribute advice_kind.
-
#advised_object ⇒ Object
(also: #target_object)
Returns the value of attribute advised_object.
-
#block_for_method ⇒ Object
Returns the value of attribute block_for_method.
-
#current_advice_node ⇒ Object
Returns the value of attribute current_advice_node.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#proceed_proc ⇒ Object
Returns the value of attribute proceed_proc.
-
#raised_exception ⇒ Object
Returns the value of attribute raised_exception.
-
#returned_value ⇒ Object
Returns the value of attribute returned_value.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==, #===)
-
#initialize(options = {}) ⇒ Context
constructor
A new instance of Context.
- #inspect ⇒ Object
- #invoke_original_join_point(enclosing_join_point, *args, &block) ⇒ Object
- #proceed(enclosing_join_point, *args, &block) ⇒ Object
- #to_s ⇒ Object
- #update(options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Context
Returns a new instance of Context.
32 33 34 |
# File 'lib/aquarium/aspects/join_point.rb', line 32 def initialize = {} update end |
Instance Attribute Details
#advice_kind ⇒ Object
Returns the value of attribute advice_kind.
25 26 27 |
# File 'lib/aquarium/aspects/join_point.rb', line 25 def advice_kind @advice_kind end |
#advised_object ⇒ Object Also known as: target_object
Returns the value of attribute advised_object.
25 26 27 |
# File 'lib/aquarium/aspects/join_point.rb', line 25 def advised_object @advised_object end |
#block_for_method ⇒ Object
Returns the value of attribute block_for_method.
26 27 28 |
# File 'lib/aquarium/aspects/join_point.rb', line 26 def block_for_method @block_for_method end |
#current_advice_node ⇒ Object
Returns the value of attribute current_advice_node.
25 26 27 |
# File 'lib/aquarium/aspects/join_point.rb', line 25 def current_advice_node @current_advice_node end |
#parameters ⇒ Object
Returns the value of attribute parameters.
25 26 27 |
# File 'lib/aquarium/aspects/join_point.rb', line 25 def parameters @parameters end |
#proceed_proc ⇒ Object
Returns the value of attribute proceed_proc.
25 26 27 |
# File 'lib/aquarium/aspects/join_point.rb', line 25 def proceed_proc @proceed_proc end |
#raised_exception ⇒ Object
Returns the value of attribute raised_exception.
26 27 28 |
# File 'lib/aquarium/aspects/join_point.rb', line 26 def raised_exception @raised_exception end |
#returned_value ⇒ Object
Returns the value of attribute returned_value.
26 27 28 |
# File 'lib/aquarium/aspects/join_point.rb', line 26 def returned_value @returned_value end |
Instance Method Details
#<=>(other) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/aquarium/aspects/join_point.rb', line 67 def <=> other return 0 if object_id == other.object_id return 1 if other.nil? result = self.class <=> other.class return result unless result == 0 result = Advice.compare_advice_kinds self.advice_kind, other.advice_kind return result unless result == 0 result = (self.advised_object.object_id.nil? and other.advised_object.object_id.nil?) ? 0 : self.advised_object.object_id <=> other.advised_object.object_id return result unless result == 0 result = (self.parameters.nil? and other.parameters.nil?) ? 0 : self.parameters <=> other.parameters return result unless result == 0 result = (self.returned_value.nil? and other.returned_value.nil?) ? 0 : self.returned_value <=> other.returned_value return result unless result == 0 (self.raised_exception.nil? and other.raised_exception.nil?) ? 0 : self.raised_exception <=> other.raised_exception end |
#eql?(other) ⇒ Boolean Also known as: ==, ===
83 84 85 |
# File 'lib/aquarium/aspects/join_point.rb', line 83 def eql? other (self <=> other) == 0 end |
#inspect ⇒ Object
61 62 63 64 65 |
# File 'lib/aquarium/aspects/join_point.rb', line 61 def inspect "JoinPoint::Context: {advice_kind = #{advice_kind}, advised_object = #{advised_object}, parameters = #{parameters}, " + "proceed_proc = #{proceed_proc}, current_advice_node = #{current_advice_node.inspect}, returned_value = #{returned_value}, " + "raised_exception = #{raised_exception}, block_for_method = #{block_for_method}}" end |
#invoke_original_join_point(enclosing_join_point, *args, &block) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/aquarium/aspects/join_point.rb', line 52 def invoke_original_join_point enclosing_join_point, *args, &block raise ContextNotCorrectlyDefined.new("It looks like you tried to call \"JoinPoint#invoke_original_join_point\" (or \"JoinPoint::Context#invoke_original_join_point\") using a join point without a completely formed context object. (Specific error: The original join point cannot be invoked because no \"@current_advice_node\" attribute was set on the corresponding JoinPoint::Context object.)") if @current_advice_node.nil? enclosing_join_point.context.parameters = args unless args.nil? or args.empty? enclosing_join_point.context.block_for_method = block if block current_advice_node.invoke_original_join_point enclosing_join_point end |
#proceed(enclosing_join_point, *args, &block) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/aquarium/aspects/join_point.rb', line 45 def proceed enclosing_join_point, *args, &block raise ProceedMethodNotAvailable.new("It looks like you tried to call \"JoinPoint#proceed\" (or \"JoinPoint::Context#proceed\") from within advice that isn't \"around\" advice. Only around advice can call proceed. (Specific error: JoinPoint#proceed cannot be invoked because no \"@proceed_proc\" attribute was set on the corresponding JoinPoint::Context object.)") if @proceed_proc.nil? enclosing_join_point.context.parameters = args unless args.nil? or args.empty? enclosing_join_point.context.block_for_method = block if block proceed_proc.call enclosing_join_point end |
#to_s ⇒ Object
59 |
# File 'lib/aquarium/aspects/join_point.rb', line 59 alias :to_s :inspect |
#update(options) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/aquarium/aspects/join_point.rb', line 36 def update .each do |key, value| instance_variable_set "@#{key}", value end @advice_kind ||= Advice::UNKNOWN_ADVICE_KIND @advised_object ||= NIL_OBJECT @parameters ||= [] end |