Class: Teapot::Command::Visualize::Targets

Inherits:
Selection
  • Object
show all
Defined in:
lib/teapot/command/visualize.rb

Overview

Visualize target-level dependencies.

Instance Method Summary collapse

Methods inherited from Selection

#call, #selection, #targets

Instance Method Details

#process(selection) ⇒ Object

Process and generate the target dependency visualization.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/teapot/command/visualize.rb', line 66

def process(selection)
	lines = ["flowchart LR"]
	lines << ""
	
	# Build the graph from all targets in the selection
	# The selection contains all targets loaded from packages
	selection.targets.each do |name, target|
		target.dependencies.each do |dependency|
			dependency_name = dependency.name.to_s
			
			# Create edge from target to its dependency
			if dependency.private?
				lines << "    #{sanitize_id(name)}[#{name}] -.-> #{sanitize_id(dependency_name)}[#{dependency_name}]"
			else
				lines << "    #{sanitize_id(name)}[#{name}] --> #{sanitize_id(dependency_name)}[#{dependency_name}]"
			end
		end
	end
	
	diagram = lines.join("\n")
	
	if output_path = @options[:output_path]
		File.write(output_path, diagram)
	else
		$stdout.puts diagram
	end
	
	return diagram
end