class VisualizeRuby::Runner

Attributes

calling_code[RW]

@return [String, File, Pathname, Proc] The code that calls the graphed code.

in_line_local_method_calls[W]

@param [TrueClass, FalseClass] in line body when calling methods on self. Looks better when tracing execution.

only_graphs[W]

@params [Array<String>, NilClass] When a graph has many sub-graphs only include listed.

output[R]
output_format[RW]

@return [Symbol, NilClass, String] To output DOT format as a string use String class as value.

output_path[RW]

@return [String, Pathname] Add the exe name to select a format ie. png, jpg, svg, dot…

ruby_code[RW]

@return [String, File, Pathname] The code to be graphed.

unique_nodes[W]

@param [TrueClass, FalseClass] Duplicate nodes with the same description are merged to point single node.

Public Instance Methods

graphs() click to toggle source
# File lib/visualize_ruby/runner.rb, line 50
def graphs
  graphs = builder.graphs.map(&:name).compact
  [builder.options.fetch(:label, "default")].concat(graphs)
end
in_line_local_method_calls() click to toggle source
# File lib/visualize_ruby/runner.rb, line 40
def in_line_local_method_calls
  @in_line_local_method_calls ||= traced?
end
options(opts={}) click to toggle source
# File lib/visualize_ruby/runner.rb, line 44
def options(opts={})
  opts.each do |key, value|
    public_send("#{key}=", value)
  end
end
run!() click to toggle source
# File lib/visualize_ruby/runner.rb, line 27
def run!
  @run ||= begin
    highlight_trace
    @output ||= VisualizeRuby::Graphviz.new(
      builder,
      graphs:       filter_graphs,
      unique_nodes: unique_nodes,
      only_graphs:  only_graphs,
    ).to_graph({ path: output_path, format: output_format }.compact)
  end
  self
end
trace(calling_code = nil, &block) click to toggle source

@param [String, File] @param [Proc]

# File lib/visualize_ruby/runner.rb, line 21
def trace(calling_code = nil, &block)
  @calling_code = calling_code || block
end

Private Instance Methods

builder() click to toggle source
# File lib/visualize_ruby/runner.rb, line 57
def builder
  @builder ||= VisualizeRuby::Builder.new(
    ruby_code:                  ruby_code,
    in_line_local_method_calls: in_line_local_method_calls
  ).build
end
filter_graphs() click to toggle source
# File lib/visualize_ruby/runner.rb, line 64
def filter_graphs
  if traced?
    builder.graphs.select do |g|
      g.nodes.any? { |n| n.touched > 0 }
    end
  else
    builder.graphs
  end
end
highlight_trace() click to toggle source
# File lib/visualize_ruby/runner.rb, line 86
def highlight_trace
  return unless traced?
  executed_events = VisualizeRuby::ExecutionTracer.new(
    builder,
    calling_code: calling_code
  ).trace.executed_events
  VisualizeRuby::HighlightTracer.new(
    builder:         builder,
    executed_events: executed_events
  ).highlight!
end
only_graphs() click to toggle source
# File lib/visualize_ruby/runner.rb, line 82
def only_graphs
  @only_graphs ||= nil
end
traced?() click to toggle source
# File lib/visualize_ruby/runner.rb, line 74
def traced?
  !!calling_code
end
unique_nodes() click to toggle source
# File lib/visualize_ruby/runner.rb, line 78
def unique_nodes
  @unique_nodes ||= true
end