Class: Golem::DSL::StateDef
- Inherits:
-
Object
- Object
- Golem::DSL::StateDef
- Defined in:
- lib/golem/dsl/state_def.rb
Instance Method Summary collapse
- #comment(comment) ⇒ Object
- #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 27 28 29 30 |
# 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 if [:comment] @state.comment = [:comment] end instance_eval(&block) if block end |
Instance Method Details
#comment(comment) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/golem/dsl/state_def.rb', line 48 def comment(comment) if @state.comment @state.comment += "\n#{comment}" else @state.comment = comment end end |
#enter(callback = nil, &block) ⇒ Object
36 37 38 39 40 |
# File 'lib/golem/dsl/state_def.rb', line 36 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
42 43 44 45 46 |
# File 'lib/golem/dsl/state_def.rb', line 42 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 |