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
- #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 |
# 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) 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
40 41 42 43 44 45 46 47 48 |
# File 'lib/golem/dsl/transition_def.rb', line 40 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 |
#guard(callback_or_options = {}, guard_options = {}, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/golem/dsl/transition_def.rb', line 29 def guard( = {}, = {}, &block) if .kind_of? Hash callback = block = else callback = end @transition.guards << Golem::Model::Condition.new(callback, ) end |