Method: StateMachine::StateCollection#match!

Defined in:
lib/state_machine/state_collection.rb

#match!(object) ⇒ Object

Determines the current state of the given object as configured by this state machine. If no state is found, then an ArgumentError will be raised.

Examples

class Vehicle
  state_machine :initial => :parked do
    other_states :idling
  end
end

states = Vehicle.state_machine.states

vehicle = Vehicle.new         # => #<Vehicle:0xb7c464b0 @state="parked">
states.match!(vehicle)        # => #<StateMachine::State name=:parked value="parked" initial=true>

vehicle.state = 'invalid'
states.match!(vehicle)        # => ArgumentError: "invalid" is not a known state value


79
80
81
# File 'lib/state_machine/state_collection.rb', line 79

def match!(object)
  match(object) || raise(ArgumentError, "#{machine.read(object, :state).inspect} is not a known #{machine.name} value")
end