Method: StateMachine::StateCollection#matches?
- Defined in:
- lib/state_machine/state_collection.rb
#matches?(object, name) ⇒ Boolean
Determines whether the given object is in a specific state. If the object’s current value doesn’t match the state, then this will return false, otherwise true. If the given state is unknown, then an IndexError 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.matches?(vehicle, :parked) # => true
states.matches?(vehicle, :idling) # => false
states.matches?(vehicle, :invalid) # => IndexError: :invalid is an invalid key for :name index
29 30 31 |
# File 'lib/state_machine/state_collection.rb', line 29 def matches?(object, name) fetch(name).matches?(machine.read(object, :state)) end |