class Rdepend::Printer
Constants
- EDGE_COLOR
Attributes
color[R]
Public Class Methods
new(result)
click to toggle source
Calls superclass method
# File lib/rdepend/printer.rb, line 10 def initialize(result) reset_color super(result) @seen_methods = Set.new end
Public Instance Methods
print(output, options = {})
click to toggle source
# File lib/rdepend/printer.rb, line 16 def print(output, options = {}) setup_options(options) add('digraph "Profile" {') add('ratio="2.0";', 'labelloc=t;', 'labeljust=l;') print_threads add('}') File.open(output, 'w') { |file| file.write(@contents.join("\n")) } %w(png svg).each { |ext| `dot -T#{ext} #{output} > #{output}.#{ext}` } end
Private Instance Methods
add(*args)
click to toggle source
# File lib/rdepend/printer.rb, line 83 def add(*args) @contents = (@contents || []) + [args].flatten end
grouped_methods(thread)
click to toggle source
# File lib/rdepend/printer.rb, line 53 def grouped_methods(thread) thread.methods.inject({}) { |m, method| m[method.klass_name] = (m[method.klass_name] || []) << method; m } end
print_classes(thread)
click to toggle source
# File lib/rdepend/printer.rb, line 59 def print_classes(thread) grouped_methods(thread).each do |cls, methods| print_methods(cls, methods.select { |m| @seen_methods.include?(m) }) end end
print_edges(method)
click to toggle source
# File lib/rdepend/printer.rb, line 75 def print_edges(method) method.aggregate_children.each do |child| label = "label=\"#{child.called}\/#{child.target.called}\";" label = "#{label} fontsize=8; color=#{color}; fontcolor=#{EDGE_COLOR};" add("#{method.object_id} -> #{child.target.object_id} [#{label}];") end end
print_methods(cls, methods)
click to toggle source
# File lib/rdepend/printer.rb, line 65 def print_methods(cls, methods) return if methods.empty? reset_color add("subgraph cluster_#{cls.object_id} {") add("label=\"#{cls.gsub(/\(.*\)/, '')}\";", "fontcolor=#{color};") add('fontsize=12;', "color=#{color}; shape=box; style=\"rounded\";") methods.each { |m| add("#{m.object_id};") } add('}') end
print_thread(thread)
click to toggle source
# File lib/rdepend/printer.rb, line 42 def print_thread(thread) thread.methods.sort_by(&sort_method).reverse_each do |method| name = method_name(method).split('#').last reset_color colors = "color=#{color}; fontcolor=#{color}; fontsize=10" add("#{method.object_id} [label=\"#{name}\"; #{colors}];") @seen_methods << method print_edges(method) end end
print_threads()
click to toggle source
# File lib/rdepend/printer.rb, line 33 def print_threads @result.threads.each do |thread| add("subgraph \"Thread #{thread.id}\" {") print_thread(thread) add('}') print_classes(thread) end end
reset_color()
click to toggle source
# File lib/rdepend/printer.rb, line 28 def reset_color color = (0...6).map { |_| '1234567890ABCDEF'.split(//).sample }.join @color = "\"##{color}\"" end