Class: ObjectProtocol::SatisfiableMessageExpectation

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/object_protocol/satisfiable_message_expectation.rb

Instance Method Summary collapse

Constructor Details

#initialize(protocol:, message_expectation:) ⇒ SatisfiableMessageExpectation

Returns a new instance of SatisfiableMessageExpectation.



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

def initialize(protocol:, message_expectation:)
  @protocol            = protocol
  @message_expectation = message_expectation

  @satisfied = false
end

Instance Method Details

#attempt_to_apply_sent_message(sent_message) ⇒ Object



16
17
18
19
20
21
# File 'lib/object_protocol/satisfiable_message_expectation.rb', line 16

def attempt_to_apply_sent_message(sent_message)
  return if satisfied?
  return false unless is_sent_message_applicable?(sent_message)

  @satisfied = true
end

#is_sent_message_applicable?(sent_message) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/object_protocol/satisfiable_message_expectation.rb', line 23

def is_sent_message_applicable?(sent_message)
  return false unless protocol.participant_by_name(sender.name) == sent_message.sender
  return false unless protocol.participant_by_name(receiver.name) == sent_message.receiver
  return false unless message == sent_message.name

  if arguments_specified?
    return false unless arguments == sent_message.arguments
  end

  true
end

#satisfied?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/object_protocol/satisfiable_message_expectation.rb', line 35

def satisfied?
  !!@satisfied
end

#unsatisfied?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/object_protocol/satisfiable_message_expectation.rb', line 39

def unsatisfied?
  !satisfied?
end