A super-slim (~200 loc) statemachine-like support library focussed on use in
Note that the current version behaves slightly differently, and comes with reduced features compared to the original version. If you are looking for the original version see the tag v1.1.0.rc11.
simple_states alternatives and similar gems
Based on the "State Machines" category.
Alternatively, view simple_states alternatives based on common mentions on social networks and blogs.
9.0 5.1 L4 simple_states VS AASMAASM - State machines for Ruby classes (plain Ruby, ActiveRecord, Mongoid, NoBrainer, Dynamoid)
8.8 0.0 L2 simple_states VS State MachineAdds support for creating state machines for attributes on any Ruby class
5.1 1.8 L4 simple_states VS state_machinesAdds support for creating state machines for attributes on any Ruby class
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of simple_states or a related project?
A super-slim (~200 loc) statemachine-like support library focussed on use in Travis CI.
Note that the current version behaves slightly differently, and comes with
reduced features compared to the original version. If you are looking for the
original version see the tag
Define states and events like this:
class Foo include SimpleStates event :start, if: :start? event :finish, to: [:passed, :failed], after: :notify, unless: :finished? attr_accessor :state, :started_at, :finished_at def start # start foo end def start? true end def notify(event) # notify about event on foo end end
SimpleStates expects your model to support attribute accessors for
Event options have the following well-known meanings:
:to # allowed target states to transition to, deferred from the event name if not given :if # only proceed if the given method returns true :unless # only proceed if the given method returns false :before # run the given method before running `super` and setting the new state :after # run the given method at the very end
All of these options except can be given as a single symbol or string or as an Array of symbols or strings.
event will effectively add methods to a proxy module which is
prepended to your class (included to the singleton class of your class'
instances on 1.9). E.g. declaring
event :start in the example above will add
start! to a module included to the singleton class of
This method will
- check if
:unlessconditions apply (if given) and just return from the method otherwise
:beforecallbacks (if given)
- set the object's
stateto the target state
- set the object's
Time.nowif the object defines a writer for it
superif Foo defines the current method (i.e. call
finishin the example above)
:aftercallbacks (if given)
You can define options for all events like so:
event :finish, after: :cleanup event :all, after: :notify
This will call :cleanup first and then :notify on :finish.
If no target state was given for an event then SimpleStates will try to derive
it from the event name. I.e. for an event
start it will check the states
list for a state
started and use it. If it can not find a target state this
way then it will raise an exception.