Class: Golem::DSL::TransitionDef
- Inherits:
-
Object
- Object
- Golem::DSL::TransitionDef
- Defined in:
- lib/golem/dsl/transition_def.rb
Instance Method Summary collapse
- #action(callback = nil, &block) ⇒ Object
- #comment(comment) ⇒ Object
- #guard(callback_or_options = {}, guard_options = {}, &block) ⇒ Object
-
#initialize(machine, event, from_state, options = {}, &block) ⇒ TransitionDef
constructor
A new instance of TransitionDef.
Constructor Details
#initialize(machine, event, from_state, options = {}, &block) ⇒ TransitionDef
Returns a new instance of TransitionDef.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/golem/dsl/transition_def.rb', line 7 def initialize(machine, event, from_state, = {}, &block) @machine = machine @event = event @from = from_state if [:to].blank? || [:to] == :self @to = [:to] = @state else @to = @machine.get_or_define_state([:to]) end callbacks = {} callbacks[:on_transition] = [:action] if [:action] @transition = Golem::Model::Transition.new(@from, @to || @from, [:guards], callbacks) if [:comment] @transition.comment = [:comment] end instance_eval(&block) if block @from.transitions_on_event[@event] ||= [] @from.transitions_on_event[@event] << @transition end |
Instance Method Details
#action(callback = nil, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/golem/dsl/transition_def.rb', line 44 def action(callback = nil, &block) #if @transition.callbacks[:on_transition] # puts "WARNING: Overriding event action for #{@transition.to_s.inspect}." #end callback = block unless callback @transition.callbacks[:on_transition] = Golem::Model::Callback.new(callback) end |
#comment(comment) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/golem/dsl/transition_def.rb', line 54 def comment(comment) if @transition.comment @transition.comment += "\n#{comment}" else @transition.comment = comment end end |
#guard(callback_or_options = {}, guard_options = {}, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/golem/dsl/transition_def.rb', line 33 def guard( = {}, = {}, &block) if .kind_of? Hash callback = block = else callback = end @transition.guards << Golem::Model::Condition.new(callback, ) end |