Name: statesman-events
Owner: GoCardless
Description: Event support for Statesman
Created: 2015-12-05 14:53:49.0
Updated: 2018-01-02 22:30:38.0
Pushed: 2016-05-24 06:06:48.0
Size: 7
Language: Ruby
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Event support for Statesman.
install statesman-events
s TaskStateMachine
clude Statesman::Machine
clude Statesman::Events
ate :unstarted, initial: true
ate :started
ate :finished
ate :cancelled
ent :start do
transition from: :unstarted, to: :started
d
ent :finish do
transition from: :started, to: :finished
d
ent :cancel do
transition from: :unstarted, to: :cancelled
transition from: :started, to: :cancelled
d
ent :restart do
transition from: :finished, to: :started
transition from: :cancelled, to: :started
d
s Task < ActiveRecord::Base
legate :current_state, :trigger, :available_events, to: :state_machine
f state_machine
@state_machine ||= TaskStateMachine.new(self)
d
= Task.new
.current_state # => "unstarted"
.trigger(:start) # => true/false
.current_state # => "started"
.available_events # => [:finish, :cancel]
Events.event
pleMachine.event(:some_event) do
ansition from: :some_state, to: :another_state
ansition from: :some_other_state, to: :yet_another_state
Define an event rule. When triggered, the first available transition from the current state will be called.
Event#trigger
ance.trigger(:some_event)
Triggers the passed event, returning true
on success. Returns false on
failure.
Event#trigger!
ance.trigger!(:some_event)
Triggers the passed event, returning true
on success. Raises
Statesman::GuardFailedError
or Statesman::TransitionFailedError
on failure.
Event#available_events
ance.available_events
Returns an array of events you can trigger
from the current state.
GoCardless ? open source. If you do too, come join us.