Class: Mocha::StateMachine
- Inherits:
-
Object
- Object
- Mocha::StateMachine
- Defined in:
- lib/mocha/state_machine.rb
Overview
Defined Under Namespace
Classes: State, StatePredicate
Instance Method Summary collapse
-
#become(next_state_name) ⇒ Object
Put the StateMachine into the
next_state_name
. -
#is(state_name) ⇒ StatePredicate, State
Provides mechanisms to (a) determine whether the StateMachine is in a given state; or (b) to change the StateMachine into the given state.
-
#is_not(unexpected_state_name) ⇒ StatePredicate
Provides a mechanism to determine whether the StateMachine is not in the state specified by
unexpected_state_name
at some point in the future. -
#starts_as(initial_state_name) ⇒ StateMachine
Put the StateMachine into the state specified by
initial_state_name
.
Instance Method Details
#become(next_state_name) ⇒ Object
Put the Mocha::StateMachine into the next_state_name
.
60 61 62 |
# File 'lib/mocha/state_machine.rb', line 60 def become(next_state_name) @current_state = next_state_name end |
#is(expected_state_name) ⇒ StatePredicate #is(desired_state_name) ⇒ State
Provides mechanisms to (a) determine whether the Mocha::StateMachine is in a given state; or (b) to change the Mocha::StateMachine into the given state.
78 79 80 |
# File 'lib/mocha/state_machine.rb', line 78 def is(state_name) State.new(self, state_name, 'is') { |current, given| current == given } end |
#is_not(unexpected_state_name) ⇒ StatePredicate
Provides a mechanism to determine whether the Mocha::StateMachine is not in the state specified by unexpected_state_name
at some point in the future.
86 87 88 |
# File 'lib/mocha/state_machine.rb', line 86 def is_not(unexpected_state_name) # rubocop:disable Naming/PredicateName StatePredicate.new(self, unexpected_state_name, 'is not') { |current, given| current != given } end |
#starts_as(initial_state_name) ⇒ StateMachine
Put the Mocha::StateMachine into the state specified by initial_state_name
.
52 53 54 55 |
# File 'lib/mocha/state_machine.rb', line 52 def starts_as(initial_state_name) become(initial_state_name) self end |