class Stealth::Flow::Specification

Attributes

flow_name[R]
initial_state[RW]
states[RW]

Public Class Methods

new(flow_name, &specification) click to toggle source
# File lib/stealth/flow/specification.rb, line 10
def initialize(flow_name, &specification)
  @states = Hash.new
  @flow_name = flow_name
  instance_eval(&specification)
end

Public Instance Methods

state_names() click to toggle source
# File lib/stealth/flow/specification.rb, line 16
def state_names
  states.keys
end

Private Instance Methods

get_fail_or_redirect_state(specified_state) click to toggle source
# File lib/stealth/flow/specification.rb, line 37
def get_fail_or_redirect_state(specified_state)
  if specified_state.present?
    session = Stealth::Session.new

    if Stealth::Session.is_a_session_string?(specified_state)
      session.session = specified_state
    else
      session.session = Stealth::Session.canonical_session_slug(
        flow: flow_name,
        state: specified_state
      )
    end

    return session
  end
end
state(name, fails_to: nil, redirects_to: nil) click to toggle source
# File lib/stealth/flow/specification.rb, line 22
def state(name, fails_to: nil, redirects_to: nil)
  fail_state = get_fail_or_redirect_state(fails_to)
  redirect_state = get_fail_or_redirect_state(redirects_to)

  new_state = Stealth::Flow::State.new(
    name: name,
    spec: self,
    fails_to: fail_state,
    redirects_to: redirect_state
  )

  @initial_state = new_state if @states.empty?
  @states[name.to_sym] = new_state
end