class StateGate::Engine

Description

Contains a list of the state-gate defined states, allowed transitions and configuration options.

The engine is queried by all helper methods to validate states and allowed transitions.

Public Class Methods

new(klass, attribute, &config) click to toggle source

Initialize the engine, setting the Class and attribute for the new engine and parsing the provided configuration.

StateGate::Engine.new(MyKlass, :status) do
  ... configuration ...
end
# File lib/state_gate/engine.rb, line 38
def initialize(klass, attribute, &config)
  aerror(:klass_type_err)            unless klass.respond_to?(:to_s)
  aerror(:attribute_type_err)        unless attribute.is_a?(Symbol)
  aerror(:missing_config_block_err)  unless block_given?

  @klass     = klass
  @attribute = StateGate.symbolize(attribute)

  set_defaults

  parse_configuration(&config)
end

Private Instance Methods

set_defaults() click to toggle source

Set the class variables with default values

# File lib/state_gate/engine.rb, line 54
def set_defaults
  @states         = {}
  @default        = nil
  @prefix         = nil
  @suffix         = nil
  @scopes         = true
  @sequential     = false
  @transitionless = false
end