Class: CheapAdvice::ActivationRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/cheap_advice.rb

Overview

Represents the activation record of a method invocation.

Constant Summary collapse

DELEGATE_TO_ADVISED =

This methods are delegated to #advised.

[ :advice, :mod, :meth, :kind, :meth_to_s ].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ActivationRecord

Returns a new instance of ActivationRecord.



484
485
486
# File 'lib/cheap_advice.rb', line 484

def initialize *args
  @advised, @rcvr, @args, @block = *args
end

Instance Attribute Details

#advisedObject (readonly)

The Advised method binding object.



461
462
463
# File 'lib/cheap_advice.rb', line 461

def advised
  @advised
end

#argsObject

The original message receiver, arguments and block (if given). Can be modified by the advice blocks.



465
466
467
# File 'lib/cheap_advice.rb', line 465

def args
  @args
end

#blockObject

The original message receiver, arguments and block (if given). Can be modified by the advice blocks.



465
466
467
# File 'lib/cheap_advice.rb', line 465

def block
  @block
end

#dataObject

Arbitrary data accessed by #[], #[]=. Advice blocks can use this to store arbitrary data. May be a frozen, empty Hash.



482
483
484
# File 'lib/cheap_advice.rb', line 482

def data
  @data
end

#errorObject Also known as: exception

Any Exception rescued from the original method. Usually nil if no exception was raised; if not nil, Exception is reraised after the :around advice block. Can be modified by the :after advice block.



475
476
477
# File 'lib/cheap_advice.rb', line 475

def error
  @error
end

#rcvrObject

The original message receiver, arguments and block (if given). Can be modified by the advice blocks.



465
466
467
# File 'lib/cheap_advice.rb', line 465

def rcvr
  @rcvr
end

#resultObject

The original message return result available in the :around or :after advice blocks. Value can be changed in the advice blocks to alter the return result.



469
470
471
# File 'lib/cheap_advice.rb', line 469

def result
  @result
end

Instance Method Details

#[](key) ⇒ Object



492
493
494
# File 'lib/cheap_advice.rb', line 492

def [] key
  (@data || EMPTY_Hash)[key]
end

#[]=(key, value) ⇒ Object



496
497
498
# File 'lib/cheap_advice.rb', line 496

def []= key, value
  (@data ||= { })[key] = value
end

#caller(offset = 0) ⇒ Object

The call stack with CheapAdvice methods filtered out.



505
506
507
# File 'lib/cheap_advice.rb', line 505

def caller(offset = 0)
  ::Kernel.caller(offset + 2)
end