Module: StateManager::DSL::State
- Included in:
- State
- Defined in:
- lib/state_manager/dsl.rb
Instance Method Summary collapse
-
#event(name, options = {}, &block) ⇒ Object
Specifies an event on the current state.
-
#initial_state(value) ⇒ Object
The initial state.
-
#state(name, klass = nil, &block) ⇒ Object
Specifies a state that is a child of the current state.
Instance Method Details
#event(name, options = {}, &block) ⇒ Object
Specifies an event on the current state
26 27 28 29 30 31 32 |
# File 'lib/state_manager/dsl.rb', line 26 def event(name, ={}, &block) name = name.to_sym event = .dup event[:name] = name specification.events[name] = event define_method name, &block if block_given? end |
#initial_state(value) ⇒ Object
The initial state
35 36 37 |
# File 'lib/state_manager/dsl.rb', line 35 def initial_state(value) specification.initial_state = value end |
#state(name, klass = nil, &block) ⇒ Object
Specifies a state that is a child of the current state
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |