module InterstateMachine::ClassMethods

Public Instance Methods

allow(event: nil, transition_to: nil, from: nil) click to toggle source
# File lib/interstate_machine.rb, line 49
def allow(event: nil, transition_to: nil, from: nil)
  define_method "#{event}_#{from.first}" do
    ensure_can_transit(event, transition_to, from, multiple: true)
  end
end
initial_state(state) click to toggle source
# File lib/interstate_machine.rb, line 23
def initial_state(state)
  @initialized_state = state
end
initialized_state() click to toggle source
# File lib/interstate_machine.rb, line 27
def initialized_state
  @initialized_state ||= []
end
machine_states() click to toggle source
# File lib/interstate_machine.rb, line 31
def machine_states
  @machine_states ||= []
end
on(event:, transition_to: nil, from: nil) { |event| ... } click to toggle source
# File lib/interstate_machine.rb, line 40
def on(event:, transition_to: nil, from: nil)
  yield(event) if block_given?
  perform_transition_by(
    event: event,
    transition_to: transition_to,
    from: from
  )
end
transition_table(*states) { || ... } click to toggle source
# File lib/interstate_machine.rb, line 35
def transition_table(*states)
  @machine_states = states
  yield
end

Private Instance Methods

perform_transition_by(event: nil, transition_to: nil, from: nil) click to toggle source
# File lib/interstate_machine.rb, line 57
def perform_transition_by(event: nil, transition_to: nil, from: nil)
  define_method event do
    evaluate_transition(event, transition_to, from)
    action = constantize(interactor_name(event)).call(object: self)
    action.success? ? @state_machine.next : action.error
  end
end