Class: Pod::Command::Why

Inherits:
Pod::Command show all
Defined in:
lib/pod/command/why.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Why

Returns a new instance of Why.



27
28
29
30
31
32
33
34
35
# File 'lib/pod/command/why.rb', line 27

def initialize(argv)
  super
  @source = argv.shift_argument
  @target = argv.shift_argument
  @reverse = argv.flag?('reverse')
  @to_yaml = argv.option('to-yaml')
  @to_dot = argv.option('to-dot')
  @cache = argv.option('cache')
end

Class Method Details

.optionsObject



18
19
20
21
22
23
24
25
# File 'lib/pod/command/why.rb', line 18

def self.options
  [
    ['--reverse', 'Shows reverse dependencies (what depends on the source instead of what the source depends on). Only valid when target is omitted.'],
    ['--to-yaml=FILE', 'Output the results in YAML format to the given file'],
    ['--to-dot=FILE', 'Output the results in DOT (GraphViz) format to the given file'],
    ['--cache=FILE', 'Load the dependency data from the given YAML file (created previously with the "query" command) instead of from the current CocoaPods instance']
  ].concat(super)
end

Instance Method Details

#runObject



42
43
44
45
46
47
48
# File 'lib/pod/command/why.rb', line 42

def run
  UI.puts 'Loading dependencies...'
  all_dependencies = all_dependencies(targets)
  [@source, @target].compact.each { |pod| help! "Cannot find pod named #{pod}" if all_dependencies[pod].nil? }
  graph = make_graph(all_dependencies)
  @target.nil? ? find_dependencies(@source, graph, @reverse) : find_all_dependency_paths(@source, @target, graph)
end

#search(source, target, graph, all_paths) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/pod/command/why.rb', line 128

def search(source, target, graph, all_paths)
  return all_paths[source] if all_paths.key?(source)
  return [[target]] if source == target
  source_paths = []
  graph.each_adjacent(source) { |v| source_paths += search(v, target, graph, all_paths) }
  all_paths[source] = source_paths.map { |path| [source] + path }
end

#validate!Object



37
38
39
40
# File 'lib/pod/command/why.rb', line 37

def validate!
  super
  help! if @source.nil?
end