Sha256: 07304c9815da1f2f66f9cda350df0d7306a9a846dc12d2d1902b7a7c3b53cf95

Contents?: true

Size: 781 Bytes

Versions: 5

Compression:

Stored size: 781 Bytes

Contents

module Stateflow
  class Machine
    attr_accessor :states, :initial_state, :events
    
    def initialize(&machine)
      @states, @events = Hash.new, Hash.new
      instance_eval(&machine)
    end
    
    def state_column(name = nil)
      @state_column ||= name.nil? ? :state : name
    end

    private    
    def initial(name)
      @initial_state_name = name
    end
    
    def state(*names, &options)
      names.each do |name|
        state = Stateflow::State.new(name, &options)
        @initial_state = state if @states.empty? || @initial_state_name == name
        @states[name.to_sym] = state
      end
    end
    
    def event(name, &transitions)
      event = Stateflow::Event.new(name, self, &transitions)
      @events[name.to_sym] = event
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
stateflow-0.4.1 lib/stateflow/machine.rb
stateflow-0.4.0 lib/stateflow/machine.rb
stateflow-0.3.0 lib/stateflow/machine.rb
stateflow-0.2.3 lib/stateflow/machine.rb
stateflow-0.2.2 lib/stateflow/machine.rb