Sha256: 9b582849a17a73f427c82d6ff1ef4ed487095adf6e1cf9d7d007410191c32d09

Contents?: true

Size: 1008 Bytes

Versions: 9

Compression:

Stored size: 1008 Bytes

Contents

module Workflow
  class State
    attr_accessor :name, :events, :meta, :on_entry, :on_exit
    attr_reader :spec

    def initialize(name, spec, meta = {})
      @name, @spec, @events, @meta = name, spec, EventCollection.new, meta
    end

    def draw(graph)
      defaults = {
        :label => to_s,
        :width => '1',
        :height => '1',
        :shape => 'ellipse'
      }

      node = graph.add_nodes(to_s, defaults.merge(meta))

      # Add open arrow for initial state
      # graph.add_edge(graph.add_node('starting_state', :shape => 'point'), node) if initial?

      node
    end


    if RUBY_VERSION >= '1.9'
      include Comparable
      def <=>(other_state)
        states = spec.states.keys
        raise ArgumentError, "state `#{other_state}' does not exist" unless states.include?(other_state.to_sym)
        states.index(self.to_sym) <=> states.index(other_state.to_sym)
      end
    end

    def to_s
      "#{name}"
    end

    def to_sym
      name.to_sym
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
workflow-3.1.1 lib/workflow/state.rb
workflow-3.1.0.pre lib/workflow/state.rb
workflow-3.1.0 lib/workflow/state.rb
workflow-3.0.0 lib/workflow/state.rb
workflow-2.0.2 lib/workflow/state.rb
workflow-2.0.1 lib/workflow/state.rb
workflow-2.0.0 lib/workflow/state.rb
workflow-2.0.0.pre lib/workflow/state.rb
workflow-1.2.0 lib/workflow/state.rb