Sha256: 0eb5934c2f9d7886e1237c194019c0e6650f00ddb47b765cec1c75a860e5715c

Contents?: true

Size: 674 Bytes

Versions: 1

Compression:

Stored size: 674 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

    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, &transitions)
      @events[name.to_sym] = event
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stateflow-0.0.1 lib/stateflow/machine.rb