module InterstateMachine::Base::InstanceMethods

Public Instance Methods

states() click to toggle source
# File lib/interstate_machine/base/instance_methods.rb, line 5
def states
  state_machine.states
end

Private Instance Methods

constantize(event) click to toggle source
# File lib/interstate_machine/base/instance_methods.rb, line 38
def constantize(event)
  Object.const_get(event.to_s.split('_').collect(&:capitalize).join)
end
ensure_can_transit(event, transition_to, from, multiple: false) click to toggle source
# File lib/interstate_machine/base/instance_methods.rb, line 21
def ensure_can_transit(event, transition_to, from, multiple: false)
  @state_machine.evaluate_transition_by!(
    Interactor::Context.new(
      event: event, transition_to: transition_to, from: from,
      multiple: multiple, object: self
    )
  )
end
evaluate_transition(event, transition_to, from) click to toggle source
# File lib/interstate_machine/base/instance_methods.rb, line 11
def evaluate_transition(event, transition_to, from)
  if event_with_multiple_state_transition?(event, transition_to, from)
    send("#{event}_#{state}")
  elsif event_with_single_state_transition?(event, transition_to, from)
    ensure_can_transit(event, transition_to, from)
  else
    raise "cannot transition via #{event} from #{state}"
  end
end
event_with_multiple_state_transition?(event, _transition_to, _from) click to toggle source
# File lib/interstate_machine/base/instance_methods.rb, line 34
def event_with_multiple_state_transition?(event, _transition_to, _from)
  respond_to?("#{event}_#{state}")
end
event_with_single_state_transition?(event, transition_to, from) click to toggle source
# File lib/interstate_machine/base/instance_methods.rb, line 30
def event_with_single_state_transition?(event, transition_to, from)
  respond_to?(event) && transition_to && from
end
interactor_name(event) click to toggle source
# File lib/interstate_machine/base/instance_methods.rb, line 42
def interactor_name(event)
  if state_machine.context.multiple
    "#{event}_#{state_machine.next_state}"
  else
    event
  end
end