Class: Golem::DSL::StateDef
- Inherits:
-
Object
- Object
- Golem::DSL::StateDef
- Defined in:
- lib/golem/dsl/state_def.rb
Instance Method Summary collapse
- #enter(callback = nil, &block) ⇒ Object
- #exit(callback = nil, &block) ⇒ Object
-
#initialize(machine, state_name, options = {}, &block) ⇒ StateDef
constructor
A new instance of StateDef.
- #on(event_name, options = {}, &block) ⇒ Object
Constructor Details
#initialize(machine, state_name, options = {}, &block) ⇒ StateDef
Returns a new instance of StateDef.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/golem/dsl/state_def.rb', line 12 def initialize(machine, state_name, = {}, &block) @machine = machine @state = @machine.get_or_define_state(state_name) @options = if [:enter] @state.callbacks[:on_enter] = Golem::Model::Callback.new([:enter]) end if [:exit] @state.callbacks[:on_exit] = Golem::Model::Callback.new([:exit]) end instance_eval(&block) if block end |
Instance Method Details
#enter(callback = nil, &block) ⇒ Object
32 33 34 35 36 |
# File 'lib/golem/dsl/state_def.rb', line 32 def enter(callback = nil, &block) raise Golem::DefinitionSyntaxError, "Enter action already set." if @state.callbacks[:on_enter] raise Golem::DefinitionSyntaxError, "Provide either a callback method or a block, not both." if callback && block @state.callbacks[:on_enter] = Golem::Model::Callback.new(block || callback) end |
#exit(callback = nil, &block) ⇒ Object
38 39 40 41 42 |
# File 'lib/golem/dsl/state_def.rb', line 38 def exit(callback = nil, &block) raise Golem::DefinitionSyntaxError, "Exit action already set." if @state.callbacks[:on_exit] raise Golem::DefinitionSyntaxError, "Provide either a callback method or a block, not both." if callback && block @state.callbacks[:on_exit] = Golem::Model::Callback.new(block || callback) end |