# class StateMachine

### Public Class Methods

new() click to toggle source

A silly little state machine.

    # File lib/puppet/type/zone.rb, line 11
    def initialize
      @state = {}
      @sequence = []
      @state_aliases = {}
      @default = nil
    end

### Public Instance Methods

alias_state(state, salias) click to toggle source

    # File lib/puppet/type/zone.rb, line 24
    def alias_state(state, salias)
      @state_aliases[state] = salias
    end

cmp?(a,b) click to toggle source

    # File lib/puppet/type/zone.rb, line 46
    def cmp?(a,b)
      index(a) < index(b)
    end

index(state) click to toggle source

    # File lib/puppet/type/zone.rb, line 32
    def index(state)
      @sequence.index(name(state))
    end

insert_state(name, transitions) click to toggle source

The order of calling #insert_state is important

    # File lib/puppet/type/zone.rb, line 19
    def insert_state(name, transitions)
      @sequence << name
      @state[name] = transitions
    end

name(n) click to toggle source

    # File lib/puppet/type/zone.rb, line 28
    def name(n)
      @state_aliases[n.to_sym] || n.to_sym
    end

sequence(fs, ss) click to toggle source

return all states between fs and ss excluding fs

    # File lib/puppet/type/zone.rb, line 37
    def sequence(fs, ss)
      fi = index(fs)
      si= index(ss)
      (if fi > si
        then @sequence[si .. fi].map{|i| @state[i]}.reverse
        else @sequence[fi .. si].map{|i| @state[i]}
      end)[1..-1]
    end