Class: Pod::Command::Dependencies
- Inherits:
-
Pod::Command
- Object
- Pod::Command
- Pod::Command::Dependencies
- Defined in:
- lib/pod/command/dependencies.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dependencies ⇒ Object
- #graphviz_data ⇒ Object
- #graphviz_dot_output ⇒ Object
- #graphviz_image_output ⇒ Object
-
#initialize(argv) ⇒ Dependencies
constructor
A new instance of Dependencies.
-
#output_file_basename ⇒ Object
Basename to use for output files.
-
#pod_to_dependencies ⇒ Object
Returns a [String: [String]] containing resolved mappings from the name of a pod to an array of the names of its dependencies.
- #podfile ⇒ Object
-
#podfile_dependencies ⇒ Object
Returns a Set of Strings of the names of dependencies specified in the Podfile.
-
#podspec_dependencies ⇒ Object
Returns a [String] of the names of dependencies specified in the podspec.
- #run ⇒ Object
- #sandbox ⇒ Object
-
#sanitized_pod_name(name) ⇒ Object
Truncates the input string after a pod’s name removing version requirements, etc.
- #validate! ⇒ Object
- #yaml_output ⇒ Object
Constructor Details
#initialize(argv) ⇒ Dependencies
Returns a new instance of Dependencies.
25 26 27 28 29 30 31 32 |
# File 'lib/pod/command/dependencies.rb', line 25 def initialize(argv) @podspec_name = argv.shift_argument @ignore_lockfile = argv.flag?('ignore-lockfile', false) @repo_update = argv.flag?('repo-update', false) @produce_graphviz_output = argv.flag?('graphviz', false) @produce_image_output = argv.flag?('image', false) super end |
Class Method Details
.arguments ⇒ Object
19 20 21 22 23 |
# File 'lib/pod/command/dependencies.rb', line 19 def self.arguments [ CLAide::Argument.new('PODSPEC', false) ].concat(super) end |
.options ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/pod/command/dependencies.rb', line 10 def self. [ ['--ignore-lockfile', 'Whether the lockfile should be ignored when calculating the dependency graph'], ['--repo-update', 'Fetch external podspecs and run `pod repo update` before calculating the dependency graph'], ['--graphviz', 'Outputs the dependency graph in Graphviz format to <podspec name>.gv or Podfile.gv'], ['--image', 'Outputs the dependency graph as an image to <podsepc name>.png or Podfile.png'], ].concat(super) end |
Instance Method Details
#dependencies ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pod/command/dependencies.rb', line 61 def dependencies @dependencies ||= begin analyzer = Installer::Analyzer.new( sandbox, podfile, @ignore_lockfile || @podspec ? nil : config.lockfile ) integrate_targets = config.integrate_targets skip_repo_update = config.skip_repo_update? config.integrate_targets = false config.skip_repo_update = !@repo_update specs = analyzer.analyze(@repo_update || @podspec).specs_by_target.values.flatten(1) config.integrate_targets = integrate_targets config.skip_repo_update = skip_repo_update lockfile = Lockfile.generate(podfile, specs, {}) pods = lockfile.to_hash['PODS'] end end |
#graphviz_data ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/pod/command/dependencies.rb', line 109 def graphviz_data @graphviz ||= begin require 'graphviz' graph = GraphViz::new(output_file_basename, :type => :digraph) root = graph.add_node(output_file_basename) unless @podspec podfile_dependencies.each do |pod| pod_node = graph.add_node(pod) graph.add_edge(root, pod_node) end end pod_to_dependencies.each do |pod, dependencies| pod_node = graph.add_node(sanitized_pod_name(pod)) dependencies.each do |dependency| dep_node = graph.add_node(sanitized_pod_name(dependency)) graph.add_edge(pod_node, dep_node) end end graph end end |
#graphviz_dot_output ⇒ Object
170 171 172 |
# File 'lib/pod/command/dependencies.rb', line 170 def graphviz_dot_output graphviz_data.output( :dot => "#{output_file_basename}.gv") end |
#graphviz_image_output ⇒ Object
166 167 168 |
# File 'lib/pod/command/dependencies.rb', line 166 def graphviz_image_output graphviz_data.output( :png => "#{output_file_basename}.png") end |
#output_file_basename ⇒ Object
Basename to use for output files.
155 156 157 158 |
# File 'lib/pod/command/dependencies.rb', line 155 def output_file_basename return 'Podfile' unless @podspec_name File.basename(@podspec_name, File.extname(@podspec_name)) end |
#pod_to_dependencies ⇒ Object
Returns a [String: [String]] containing resolved mappings from the name of a pod to an array of the names of its dependencies.
150 151 152 |
# File 'lib/pod/command/dependencies.rb', line 150 def pod_to_dependencies dependencies.map { |d| d.is_a?(Hash) ? d : { d => [] } }.reduce({}) { |combined, individual| combined.merge!(individual) } end |
#podfile ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pod/command/dependencies.rb', line 82 def podfile @podfile ||= begin if podspec = @podspec platform = podspec.available_platforms.first platform_name, platform_version = platform.name, platform.deployment_target.to_s sources = SourcesManager.all.map(&:url) Podfile.new do sources.each { |s| source s } platform platform_name, platform_version pod podspec.name, podspec: podspec.defined_in_file end else verify_podfile_exists! config.podfile end end end |
#podfile_dependencies ⇒ Object
Returns a Set of Strings of the names of dependencies specified in the Podfile.
140 141 142 |
# File 'lib/pod/command/dependencies.rb', line 140 def podfile_dependencies Set.new(podfile.target_definitions.values.map { |t| t.dependencies.map { |d| d.name } }.flatten) end |
#podspec_dependencies ⇒ Object
Returns a [String] of the names of dependencies specified in the podspec.
145 146 147 |
# File 'lib/pod/command/dependencies.rb', line 145 def podspec_dependencies @podspec.all_dependencies.map { |d| d.name } end |
#run ⇒ Object
54 55 56 57 58 59 |
# File 'lib/pod/command/dependencies.rb', line 54 def run require 'yaml' graphviz_image_output if @produce_image_output graphviz_dot_output if @produce_graphviz_output yaml_output end |
#sandbox ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/pod/command/dependencies.rb', line 100 def sandbox if @podspec require 'tmpdir' Sandbox.new(Dir.mktmpdir) else config.sandbox end end |
#sanitized_pod_name(name) ⇒ Object
Truncates the input string after a pod’s name removing version requirements, etc.
135 136 137 |
# File 'lib/pod/command/dependencies.rb', line 135 def sanitized_pod_name(name) Pod::Dependency.from_string(name).name end |
#validate! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pod/command/dependencies.rb', line 34 def validate! super if @podspec_name require 'pathname' path = Pathname.new(@podspec_name) if path.exist? @podspec = Specification.from_file(path) else @podspec = SourcesManager. search(Dependency.new(@podspec_name)). specification. subspec_by_name(@podspec_name) end end if (@produce_image_output || @produce_graphviz_output) && Executable.which('dot').nil? raise Informative, 'GraphViz must be installed and `dot` must be in ' \ '$PATH to produce image or graphviz output.' end end |
#yaml_output ⇒ Object
160 161 162 163 164 |
# File 'lib/pod/command/dependencies.rb', line 160 def yaml_output UI.title 'Dependencies' do UI.puts dependencies.to_yaml end end |