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, line 32
def initialize options = {}
  update options
end

Public Instance Methods

<=>(other) click to toggle source
# 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
==(other) click to toggle source
Alias for: eql?
===(other) click to toggle source
Alias for: eql?
eql?(other) click to toggle source
# File lib/aquarium/aspects/join_point.rb, line 83
def eql? other
  (self <=> other) == 0
end
Also aliased as: ==, ===
inspect() click to toggle source
# 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
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, 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) click to toggle source
# 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() click to toggle source
Alias for: inspect
update(options) click to toggle source
# File lib/aquarium/aspects/join_point.rb, line 36
def update options
  options.each do |key, value|
    instance_variable_set "@#{key}", value
  end
  @advice_kind    ||= Advice::UNKNOWN_ADVICE_KIND
  @advised_object ||= NIL_OBJECT
  @parameters     ||= []
end