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
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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pod/command/dependencies.rb', line 58 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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/pod/command/dependencies.rb', line 106 def graphviz_data @graphviz ||= begin 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
167 168 169 |
# File 'lib/pod/command/dependencies.rb', line 167 def graphviz_dot_output graphviz_data.output( :dot => "#{output_file_basename}.gv") end |
#graphviz_image_output ⇒ Object
163 164 165 |
# File 'lib/pod/command/dependencies.rb', line 163 def graphviz_image_output graphviz_data.output( :png => "#{output_file_basename}.png") end |
#output_file_basename ⇒ Object
Basename to use for output files.
152 153 154 155 |
# File 'lib/pod/command/dependencies.rb', line 152 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.
147 148 149 |
# File 'lib/pod/command/dependencies.rb', line 147 def pod_to_dependencies dependencies.map { |d| d.is_a?(Hash) ? d : { d => [] } }.reduce({}) { |combined, individual| combined.merge!(individual) } end |
#podfile ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pod/command/dependencies.rb', line 79 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.
137 138 139 |
# File 'lib/pod/command/dependencies.rb', line 137 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.
142 143 144 |
# File 'lib/pod/command/dependencies.rb', line 142 def podspec_dependencies @podspec.all_dependencies.map { |d| d.name } end |
#run ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/pod/command/dependencies.rb', line 50 def run require 'graphviz' require 'yaml' graphviz_image_output if @produce_image_output graphviz_dot_output if @produce_graphviz_output yaml_output end |
#sandbox ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/pod/command/dependencies.rb', line 97 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.
131 132 133 134 |
# File 'lib/pod/command/dependencies.rb', line 131 def sanitized_pod_name(name) match = /([\w_\/]+)( \(.*\))?/.match(name) match ? match[1] : name end |
#validate! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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 end |
#yaml_output ⇒ Object
157 158 159 160 161 |
# File 'lib/pod/command/dependencies.rb', line 157 def yaml_output UI.title 'Dependencies' do UI.puts dependencies.to_yaml end end |