class Dogviz::Flow
Constants
- FLOW_RENDERERS
Attributes
commands[R]
executor[RW]
sys[R]
Public Class Methods
new(sys, name)
click to toggle source
# File lib/dogviz/flow.rb, line 16 def initialize(sys, name) @sys = sys @name = name @commands = [] @actors = [] @caller_stack = [] @executor = nil end
Public Instance Methods
add_call(from, to, label)
click to toggle source
# File lib/dogviz/flow.rb, line 70 def add_call(from, to, label) commands << [:call, from, to, label] end
add_note(from, where, what)
click to toggle source
# File lib/dogviz/flow.rb, line 53 def add_note(from, where, what) # yukk next lets move to command classes, e.g. OptCommand, NoteCommand, CallCommand etc. commands << [:note, from, where, what] end
divider(text)
click to toggle source
# File lib/dogviz/flow.rb, line 64 def divider(text) commands << [:divider, nil, nil, text] end
end_call(label)
click to toggle source
# File lib/dogviz/flow.rb, line 79 def end_call(label) current_actor = @caller_stack.pop add_call(current_actor, @caller_stack.last, label) unless label.nil? end
ensure_is_thing(step)
click to toggle source
# File lib/dogviz/flow.rb, line 105 def ensure_is_thing(step) raise "Expected some thing or process: '#{step}' already got: #{commands}" unless step.is_a?(Thing) || step.is_a?(Process) step end
flows(*steps)
click to toggle source
# File lib/dogviz/flow.rb, line 84 def flows(*steps) sys.warn_on_exit 'deprecation warning: flow#flows deprecated, should use flow#from(actor) { <nested flow spec> }' from = nil to = nil label = nil steps.each do |step| if from.nil? from = ensure_is_thing(step) elsif label.nil? && step.is_a?(String) label = step elsif to.nil? to = ensure_is_thing(step) end unless to.nil? add_call from, to, label from = to to = label = nil end end end
from(initial_actor, &flowspec)
click to toggle source
# File lib/dogviz/flow.rb, line 36 def from(initial_actor, &flowspec) @actors.each { |actor| actor.start_flow self } @caller_stack << initial_actor begin flowspec.call rescue NoMethodError => nme raise "Did you call #involves for all actors? It's a common cause of the caught exception: #{nme}" ensure @caller_stack.pop @actors.each { |actor| actor.stop_flow } end end
involves(*actors)
click to toggle source
# File lib/dogviz/flow.rb, line 31 def involves(*actors) @actors += actors self end
make_connections()
click to toggle source
# File lib/dogviz/flow.rb, line 25 def make_connections commands.each { |type, from, to, label| thing_of(from).points_to(thing_of(to), name: label.split('\n').first) if type == :call } end
next_call(to, label)
click to toggle source
# File lib/dogviz/flow.rb, line 74 def next_call(to, label) add_call @caller_stack.last, to, label @caller_stack << to end
optional(text, &block)
click to toggle source
# File lib/dogviz/flow.rb, line 58 def optional(text, &block) commands << [:opt, nil, nil, text] block.call commands << [:end, nil, nil, nil] end
Also aliased as: opt
output(type_to_file)
click to toggle source
# File lib/dogviz/flow.rb, line 110 def output(type_to_file) type = type_to_file.keys.first raise "Only support #{FLOW_RENDERERS.keys}, not: '#{type}'" unless FLOW_RENDERERS.has_key?(type) render(FLOW_RENDERERS[type]).output(type_to_file, executor) end
render(renderer_class = SequenceRenderer)
click to toggle source
# File lib/dogviz/flow.rb, line 116 def render(renderer_class = SequenceRenderer) renderer = renderer_class.new(@name) commands.each do |type, from, to, label| if type == :call renderer.render_edge(from, to, {label: label}) elsif type == :end renderer.end_combination elsif type == :note renderer.note(from, to, label) elsif type == :divider renderer.divider(label) else renderer.start_combination(type, label) end end renderer.rendered end
suppress_messages!()
click to toggle source
# File lib/dogviz/flow.rb, line 134 def suppress_messages! sys.suppress_messages! end
Private Instance Methods
thing_of(it)
click to toggle source
# File lib/dogviz/flow.rb, line 142 def thing_of(it) return it.processor if it.is_a?(Process) it end