Class: Finity::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/finity/transition.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Transition

A transition must define at least one original state (:from) and a state it transitions to (:to).



28
29
30
31
32
33
34
# File 'lib/finity/transition.rb', line 28

def initialize options
  @from, @to, @if, @do = options.values_at(:from, :to, :if, :do)
  if @from.nil? or @to.nil?
    raise MissingCallback, 'A transition demands states at least one original ' +
                           'state (:from) and a state it transitions to (:to)'
  end
end

Instance Method Details

#handle(object) ⇒ Object

Check, whether the current transition is allowed and execute it.



37
38
39
40
41
42
# File 'lib/finity/transition.rb', line 37

def handle object
  if @if.nil? or execute object, @if
    execute object, @do unless @do.nil?
    @to
  end
end