Class: Pandan::DependencyGraph
- Defined in:
- lib/pandan/command/dependency_graph.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ DependencyGraph
constructor
A new instance of DependencyGraph.
- #run ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(argv) ⇒ DependencyGraph
Returns a new instance of DependencyGraph.
24 25 26 27 28 29 30 31 32 |
# File 'lib/pandan/command/dependency_graph.rb', line 24 def initialize(argv) @xcworkspace = argv.option('xcworkspace') @xcworkspace ||= XCWorkspace.find_workspace @save_gv = argv.flag?('graphviz') @save_png = argv.flag?('image') @filter = argv.option('filter') @filter ||= '.*' # Match everything super end |
Class Method Details
.options ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/pandan/command/dependency_graph.rb', line 11 def self. [ ['--xcworkspace=path/to/workspace', 'If not set, Pandan will try to find a workspace'], ['--graphviz', 'Outputs the dependency graph in GraphViz format'], ['--image', 'Outputs the dependency graph as a PNG image'], ['--filter=expression', 'If set, pandan will select all targets whose name match the regular expression'] ].concat(super) end |
Instance Method Details
#run ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pandan/command/dependency_graph.rb', line 46 def run parser = Parser.new(@xcworkspace, @filter) targets = parser.all_targets graph = Graph.new(false) graph.add_target_info(targets) Dir.mktmpdir do |dir| tmpfile = File.join(dir, 'dependencies.gv') tmpfile_reduced = File.join(dir, 'dependencies_reduced.gv') save_gv(graphviz_data(graph), tmpfile) `tred #{tmpfile} > #{tmpfile_reduced}` # tred performs a transitive reduction on the graph reduced_graph = GraphViz.parse(tmpfile_reduced) FileUtils.mv(tmpfile_reduced, 'dependencies.gv') if @save_gv save_png(reduced_graph, 'dependencies.png') if @save_png end end |
#validate! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pandan/command/dependency_graph.rb', line 34 def validate! super help! 'Could not find the workspace. Try setting it manually using the --xcworkspace option.' unless @xcworkspace if `which tred`.empty? help! 'Pandan requires GraphViz to generate the dependency graph. '\ 'Please install it, e.g. with Homebrew: `brew install graphviz`.' end help! 'Please use at least one of --graphviz and --image.' if @save_gv.nil? && @save_png.nil? end |