Sha256: 88bc76ef25c43b64eb6f7b9342f808e66659f3728a0a15e654dbe2fa252aa612

Contents?: true

Size: 718 Bytes

Versions: 5

Compression:

Stored size: 718 Bytes

Contents

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] if options.has_key?(:event)
    end
    
    def fire_event(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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simplificator-fsm-0.2.0 lib/fsm/transition.rb
simplificator-fsm-0.2.1 lib/fsm/transition.rb
simplificator-fsm-0.2.2 lib/fsm/transition.rb
simplificator-fsm-0.2.3 lib/fsm/transition.rb
simplificator-fsm-0.2.4 lib/fsm/transition.rb