Module: StateMachines::Graphviz::Renderer
Instance Method Summary collapse
- #draw_branch(branch, graph, event, valid_states, io = $stdout) ⇒ Object
- #draw_event(event, graph, options = {}, io = $stdout) ⇒ Object
- #draw_machine(machine, io: $stdout, **options) ⇒ Object
- #draw_state(state, graph, options = {}, io = $stdout) ⇒ Object
Instance Method Details
#draw_branch(branch, graph, event, valid_states, io = $stdout) ⇒ Object
49 50 51 52 53 |
# File 'lib/state_machines/graphviz/renderer.rb', line 49 def draw_branch(branch, graph, event, valid_states, io = $stdout) machine = event.machine draw_branch_with_label(branch, graph, event.name.to_s, machine, valid_states) true end |
#draw_event(event, graph, options = {}, io = $stdout) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/state_machines/graphviz/renderer.rb', line 37 def draw_event(event, graph, = {}, io = $stdout) machine = event.machine valid_states = machine.states.by_priority.map(&:name) event_label = [:human_name] ? event.human_name(machine.owner_class) : event.name.to_s event.branches.each do |branch| draw_branch_with_label(branch, graph, event_label, machine, valid_states) end true end |
#draw_machine(machine, io: $stdout, **options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/state_machines/graphviz/renderer.rb', line 10 def draw_machine(machine, io: $stdout, **) diagram, builder = StateMachines::Diagram::Renderer.build_state_diagram(machine, ) = .dup name = .delete(:name) || "#{machine.owner_class.name}_#{machine.name}" = { human_name: false } [:human_name] = .delete(:human_names) if .include?(:human_names) graph = Graph.new(name, ) render_diagram(graph, diagram, builder, ) graph.output graph end |
#draw_state(state, graph, options = {}, io = $stdout) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/state_machines/graphviz/renderer.rb', line 24 def draw_state(state, graph, = {}, io = $stdout) node = graph.add_nodes( state.name ? state.name.to_s : 'nil', label: state.description(), width: '1', height: '1', shape: state.final? ? 'doublecircle' : 'ellipse' ) graph.add_edges(graph.add_nodes('starting_state', shape: 'point'), node) if state.initial? true end |