Class: ObjectProtocol::Execution

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*participants, &blk) ⇒ Execution

Returns a new instance of Execution.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/object_protocol/execution.rb', line 9

def initialize(*participants, &blk)
  raise(ArgumentError, "#{self.class.name} requires a block") unless block_given?

  @participants = participants
  @blk          = blk
end

Instance Attribute Details

#participantsObject (readonly)

Returns the value of attribute participants.



7
8
9
# File 'lib/object_protocol/execution.rb', line 7

def participants
  @participants
end

Instance Method Details

#call(protocol) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/object_protocol/execution.rb', line 16

def call(protocol)
  begin
    $object_protocol_spying_enabled = false
    participants.each(&method(:start_spying_on_public_methods_on))
    # we guard inside the methods with a global so that we don't start spying
    # while we're still redefining all the public methods on the participant
    $object_protocol_spying_enabled = true
    protocol.instance_exec(&blk)
  ensure
    $object_protocol_spying_enabled = false
    participants.each(&method(:stop_spying_on_public_methods_on))
  end
end

#messagesObject



30
# File 'lib/object_protocol/execution.rb', line 30

def messages; @messages ||= []; end