Class: Decorate::AroundDecorator::AroundCall

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

Overview

An AroundCall holds the auxiliary information that is passed as argument to an around method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver, message, wrapped_message, args, block) ⇒ AroundCall

Returns a new instance of AroundCall.



29
30
31
32
33
34
35
36
# File 'lib/decorate/around_decorator.rb', line 29

def initialize(receiver, message, wrapped_message, args, block)
  @receiver = receiver
  @message = message
  @wrapped_message = wrapped_message
  @args = args
  @block = block
  @result = nil
end

Instance Attribute Details

#argsObject (readonly)

Original argument list.



21
22
23
# File 'lib/decorate/around_decorator.rb', line 21

def args
  @args
end

#blockObject (readonly)

Original block.



24
25
26
# File 'lib/decorate/around_decorator.rb', line 24

def block
  @block
end

#messageObject (readonly)

The message that was sent resulting in this around call.



14
15
16
# File 'lib/decorate/around_decorator.rb', line 14

def message
  @message
end

#receiverObject (readonly)

Receiving object.



11
12
13
# File 'lib/decorate/around_decorator.rb', line 11

def receiver
  @receiver
end

#resultObject (readonly)

Holds the result of a transfer to the wrapped method.



27
28
29
# File 'lib/decorate/around_decorator.rb', line 27

def result
  @result
end

#wrapped_messageObject (readonly)

The name of the method that constitutes the “core” behaviour (behaviour without the around logic).



18
19
20
# File 'lib/decorate/around_decorator.rb', line 18

def wrapped_message
  @wrapped_message
end

Instance Method Details

#transfer(args = @args, &block) ⇒ Object

Call the wrapped method. args and block default to original ones passed by client code. The return value of the wrapped method is stored in the result attribute and also returned from transfer.



42
43
44
45
# File 'lib/decorate/around_decorator.rb', line 42

def transfer(args = @args, &block)
  block ||= @block
  @result = @receiver.__send__(@wrapped_message, *args, &block)
end