Class: StatefulEnum::Graph::EventDrawer

Inherits:
Machine::Event show all
Defined in:
lib/generators/stateful_enum/graph_generator.rb

Instance Attribute Summary

Attributes inherited from Machine::Event

#name, #value_method_name

Instance Method Summary collapse

Methods inherited from Machine::Event

#after, #all, #before

Constructor Details

#initialize(g, states, prefix, suffix, name, &block) ⇒ EventDrawer

Returns a new instance of EventDrawer.



51
52
53
54
55
56
# File 'lib/generators/stateful_enum/graph_generator.rb', line 51

def initialize(g, states, prefix, suffix, name, &block)
  @g, @states, @prefix, @suffix, @name = g, states, prefix, suffix, name
  @before, @after = [], []

  instance_eval(&block) if block
end

Instance Method Details

#transition(transitions, options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/generators/stateful_enum/graph_generator.rb', line 58

def transition(transitions, options = {})
  if options.blank?
    transitions.delete :if
    transitions.delete :unless
  end

  transitions.each_pair do |from, to|
    Array(from).each do |f|
      @g.add_edge f.to_s, to.to_s, label: "#{@prefix}#{@name}#{@suffix}"
    end
  end
end