module StateManager::DSL::State
Public Instance Methods
event(name, options={}, &block)
click to toggle source
Specifies an event on the current state
# File lib/state_manager/dsl.rb, line 26 def event(name, options={}, &block) name = name.to_sym event = options.dup event[:name] = name specification.events[name] = event define_method name, &block if block_given? end
initial_state(value)
click to toggle source
The initial state
# File lib/state_manager/dsl.rb, line 35 def initial_state(value) specification.initial_state = value end
state(name, klass=nil, &block)
click to toggle source
Specifies a state that is a child of the current state
# File lib/state_manager/dsl.rb, line 8 def state(name, klass=nil, &block) # If no base class is specified we look for a class inside the current # state's class which has the same name as the state const_name = name.to_s.classify klass ||= if const_defined?(const_name, false) self.const_get(const_name) else Class.new(StateManager::State) end klass = Class.new(klass, &block) if block_given? remove_const const_name if const_defined?(const_name, false) const_set(const_name, klass) specification.states[name.to_sym] = klass end