class Aquarium::Aspects::JoinPoint::Context
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!
Constants
- NIL_OBJECT
Attributes
advice_kind[RW]
advised_object[RW]
block_for_method[RW]
current_advice_node[RW]
parameters[RW]
proceed_proc[RW]
raised_exception[RW]
returned_value[RW]
target_object[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/aquarium/aspects/join_point.rb 32 def initialize options = {} 33 update options 34 end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/aquarium/aspects/join_point.rb 67 def <=> other 68 return 0 if object_id == other.object_id 69 return 1 if other.nil? 70 result = self.class <=> other.class 71 return result unless result == 0 72 result = Advice.compare_advice_kinds self.advice_kind, other.advice_kind 73 return result unless result == 0 74 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 75 return result unless result == 0 76 result = (self.parameters.nil? and other.parameters.nil?) ? 0 : self.parameters <=> other.parameters 77 return result unless result == 0 78 result = (self.returned_value.nil? and other.returned_value.nil?) ? 0 : self.returned_value <=> other.returned_value 79 return result unless result == 0 80 (self.raised_exception.nil? and other.raised_exception.nil?) ? 0 : self.raised_exception <=> other.raised_exception 81 end
eql?(other)
click to toggle source
# File lib/aquarium/aspects/join_point.rb 83 def eql? other 84 (self <=> other) == 0 85 end
inspect()
click to toggle source
# File lib/aquarium/aspects/join_point.rb 61 def inspect 62 "JoinPoint::Context: {advice_kind = #{advice_kind}, advised_object = #{advised_object}, parameters = #{parameters}, " + 63 "proceed_proc = #{proceed_proc}, current_advice_node = #{current_advice_node.inspect}, returned_value = #{returned_value}, " + 64 "raised_exception = #{raised_exception}, block_for_method = #{block_for_method}}" 65 end
Also aliased as: to_s
invoke_original_join_point(enclosing_join_point, *args, &block)
click to toggle source
# File lib/aquarium/aspects/join_point.rb 52 def invoke_original_join_point enclosing_join_point, *args, &block 53 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? 54 enclosing_join_point.context.parameters = args unless args.nil? or args.empty? 55 enclosing_join_point.context.block_for_method = block if block 56 current_advice_node.invoke_original_join_point enclosing_join_point 57 end
proceed(enclosing_join_point, *args, &block)
click to toggle source
# File lib/aquarium/aspects/join_point.rb 45 def proceed enclosing_join_point, *args, &block 46 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? 47 enclosing_join_point.context.parameters = args unless args.nil? or args.empty? 48 enclosing_join_point.context.block_for_method = block if block 49 proceed_proc.call enclosing_join_point 50 end
update(options)
click to toggle source
# File lib/aquarium/aspects/join_point.rb 36 def update options 37 options.each do |key, value| 38 instance_variable_set "@#{key}", value 39 end 40 @advice_kind ||= Advice::UNKNOWN_ADVICE_KIND 41 @advised_object ||= NIL_OBJECT 42 @parameters ||= [] 43 end