lib/fsm/transition.rb in simplificator-fsm-0.1.0 vs lib/fsm/transition.rb in simplificator-fsm-0.2.0
- old
+ new
@@ -1,17 +1,21 @@
module FSM
class Transition
+ include FSM::Options::InstanceMethods
attr_accessor(:name, :from, :to, :event)
def initialize(name, from, to, options = {})
+ raise ArgumentError.new("name, from and to are required but were '#{name}', '#{from}' and '#{to}'") unless name && from && to
+ assert_options(options, [:event])
self.name = name
self.from = from
self.to = to
- self.event = Executable.new options[:event], true
+ self.event = Executable.new options[:event] if options.has_key?(:event)
end
def fire_event(target, args)
- self.event.execute(target, args)
+ self.event.execute(target, *args) if self.event
end
+
def to_s
"Transition from #{self.from.name} -> #{self.to.name} with event #{self.event}"
end
end
end
\ No newline at end of file