Class: Finity::Transition
- Inherits:
-
Object
- Object
- Finity::Transition
- Defined in:
- lib/finity/transition.rb
Instance Method Summary collapse
-
#handle(object) ⇒ Object
Check, whether the current transition is allowed and execute it.
-
#initialize(options) ⇒ Transition
constructor
A transition must define at least one original state (:from) and a state it transitions to (:to).
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 @from, @to, @if, @do = .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 |