Class: Mocha::StateMachine
Overview
A state machine that is used to constrain the order of invocations. An invocation can be constrained to occur when a state is, or is_not, active.
Defined Under Namespace
Classes: State, StatePredicate
Instance Attribute Summary collapse
-
#current_state ⇒ Object
:nodoc:.
-
#name ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#become(next_state) ⇒ Object
:call-seq: become(next_state).
-
#initialize(name) ⇒ StateMachine
constructor
:nodoc:.
-
#is(state) ⇒ Object
:call-seq: is(state).
-
#is_not(state) ⇒ Object
:call-seq: is_not(state).
-
#mocha_inspect ⇒ Object
:nodoc:.
-
#starts_as(initial_state) ⇒ Object
:call-seq: starts_as(initial_state) -> state_machine.
Constructor Details
#initialize(name) ⇒ StateMachine
:nodoc:
47 48 49 50 |
# File 'lib/mocha/state_machine.rb', line 47 def initialize(name) # :nodoc: @name = name @current_state = nil end |
Instance Attribute Details
#current_state ⇒ Object
:nodoc:
45 46 47 |
# File 'lib/mocha/state_machine.rb', line 45 def current_state @current_state end |
#name ⇒ Object (readonly)
:nodoc:
43 44 45 |
# File 'lib/mocha/state_machine.rb', line 43 def name @name end |
Instance Method Details
#become(next_state) ⇒ Object
:call-seq: become(next_state)
Put the state_machine
into the next_state
.
63 64 65 |
# File 'lib/mocha/state_machine.rb', line 63 def become(next_state) @current_state = next_state end |
#is(state) ⇒ Object
:call-seq: is(state)
Determines whether the state_machine
is in the specified state
.
70 71 72 |
# File 'lib/mocha/state_machine.rb', line 70 def is(state) State.new(self, state) end |
#is_not(state) ⇒ Object
:call-seq: is_not(state)
Determines whether the state_machine
is not in the specified state
.
77 78 79 |
# File 'lib/mocha/state_machine.rb', line 77 def is_not(state) StatePredicate.new(self, state) end |
#mocha_inspect ⇒ Object
:nodoc:
81 82 83 84 85 86 87 |
# File 'lib/mocha/state_machine.rb', line 81 def mocha_inspect # :nodoc: if @current_state "#{@name} is #{@current_state.mocha_inspect}" else "#{@name} has no current state" end end |
#starts_as(initial_state) ⇒ Object
:call-seq: starts_as(initial_state) -> state_machine
Put the state_machine
into the initial_state
.
55 56 57 58 |
# File 'lib/mocha/state_machine.rb', line 55 def starts_as(initial_state) become(initial_state) self end |