Class: Golem::DSL::DecisionDef

Inherits:
Object
  • Object
show all
Defined in:
lib/golem/dsl/decision_def.rb

Instance Method Summary collapse

Constructor Details

#initialize(machine, state, event) ⇒ DecisionDef

Returns a new instance of DecisionDef.



7
8
9
10
11
# File 'lib/golem/dsl/decision_def.rb', line 7

def initialize(machine, state, event)
  @machine = machine
  @state = state
  @event = event
end

Instance Method Details

#method_missing?Boolean

Returns:

  • (Boolean)

Raises:

  • (SyntaxError)


33
34
35
# File 'lib/golem/dsl/decision_def.rb', line 33

def method_missing?
  raise SyntaxError, "Only 'transition' declarations can be placed in a state's decision block."
end

#transition(options, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/golem/dsl/decision_def.rb', line 13

def transition(options, &block)
  if options[:to]
    to = @machine.states[options[:to]] ||= Golem::Model::State.new(options[:to])
  else
    # self-transition
    to = @state
  end

  if options[:guard] || options[:if]
     options[:guard] = Golem::Model::Callback.new(options[:guard] || options[:if]) # :guard and :if mean the same thing
  end

  if block || options[:action]
     options[:action] = Golem::Model::Callback.new(options[:action] || block)
  end
  
  @state.transitions_on_event[@event.name] ||= []
  @state.transitions_on_event[@event.name] << Golem::Model::Transition.new(@state, to, options)
end