Module: SuperState

Defined in:
lib/super_state.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods Classes: BadState, StateArray, StateGroups

Class Method Summary collapse

Class Method Details

.canonicalise(value) ⇒ Object

states should be stored as strings in all cases (if it needs to be a sym, we should explicitly ask it to be)



21
22
23
24
25
26
27
28
29
# File 'lib/super_state.rb', line 21

def self.canonicalise(value)
  if value
    if value.is_a?(Array)
      value.map{|v| self.canonicalise(v)}
    else
      value.to_s
    end
  end
end

.included(klass) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/super_state.rb', line 3

def self.included(klass)
  klass.class_eval do
    cattr_accessor :initial_super_state
    cattr_accessor :__super_states
    cattr_accessor :super_state_groups
    self.__super_states     = StateArray.new.all_states!
    self.super_state_groups = StateGroups.new
    
    extend ClassMethods
    include InstanceMethods
    
    # the initial_state only takes effect when we say record.valid?
    before_validation :set_initial_super_state, :on => :create
  end
end