Class: StatefulEnum::Graph::GraphDrawer
- Inherits:
-
Object
- Object
- StatefulEnum::Graph::GraphDrawer
- Defined in:
- lib/generators/stateful_enum/graph_generator.rb
Instance Method Summary collapse
- #event(name, &block) ⇒ Object
-
#initialize(model, column, states, prefix, suffix, &block) ⇒ GraphDrawer
constructor
A new instance of GraphDrawer.
Constructor Details
#initialize(model, column, states, prefix, suffix, &block) ⇒ GraphDrawer
Returns a new instance of GraphDrawer.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/stateful_enum/graph_generator.rb', line 24 def initialize(model, column, states, prefix, suffix, &block) @states, @prefix, @suffix = states, prefix, suffix @g = ::GraphViz.new 'G', rankdir: 'TB' states.each do |state| @g.add_node state.to_s, label: state.to_s, width: '1', height: '1', shape: 'ellipse' end if (default_value = model.columns_hash[column.to_s].default) default_label = model.defined_enums[column.to_s].key default_value.to_i # SQLite returns the default value in String @g.add_edge @g.add_node('start state', shape: 'point'), @g.get_node(default_label) end instance_eval(&block) (@g.each_edge.map(&:node_two).uniq - @g.each_edge.map(&:node_one).uniq).each do |final| @g.get_node(final) {|n| n['shape'] = 'doublecircle' } end @g.output png: File.join((ENV['DEST_DIR'] || Dir.pwd), "#{model.name}.png") end |
Instance Method Details
#event(name, &block) ⇒ Object
45 46 47 |
# File 'lib/generators/stateful_enum/graph_generator.rb', line 45 def event(name, &block) EventDrawer.new @g, @states, @prefix, @suffix, name, &block end |