Class: Pod::Command::Dependencies
- Inherits:
-
Pod::Command
- Object
- Pod::Command
- Pod::Command::Dependencies
- Includes:
- Command::ProjectDirectory
- Defined in:
- lib/pod/command/dependencies.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dependencies ⇒ Object
- #find_occurrences ⇒ 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_occurrences_in_podfile ⇒ Object
- #pod_occurrences_in_podfile_dependencies ⇒ Object
-
#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.
- #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.
28 29 30 31 32 33 34 35 36 |
# File 'lib/pod/command/dependencies.rb', line 28 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) @lib_to_find = argv.option('occurrences-of') super end |
Class Method Details
.arguments ⇒ Object
22 23 24 25 26 |
# File 'lib/pod/command/dependencies.rb', line 22 def self.arguments [ CLAide::Argument.new('PODSPEC', false) ].concat(super) end |
.options ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/pod/command/dependencies.rb', line 12 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 <podspec name>.png or Podfile.png'], ['--occurrences-of', 'Prints out pod name ocurrences'] ].concat(super) end |
Instance Method Details
#dependencies ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pod/command/dependencies.rb', line 72 def dependencies @dependencies ||= begin analyzer = Installer::Analyzer.new( sandbox, podfile, @ignore_lockfile || @podspec ? nil : config.lockfile ) specs = config.with_changes(skip_repo_update: !@repo_update) do analyzer.analyze(@repo_update || @podspec).specs_by_target.values.flatten(1) end lockfile = Lockfile.generate(podfile, specs, {}) lockfile.to_hash['PODS'] end end |
#find_occurrences ⇒ Object
178 179 180 |
# File 'lib/pod/command/dependencies.rb', line 178 def find_occurrences pod_occurrences_in_podfile + pod_occurrences_in_podfile_dependencies end |
#graphviz_data ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/pod/command/dependencies.rb', line 119 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
174 175 176 |
# File 'lib/pod/command/dependencies.rb', line 174 def graphviz_dot_output graphviz_data.output( :dot => "#{output_file_basename}.gv") end |
#graphviz_image_output ⇒ Object
170 171 172 |
# File 'lib/pod/command/dependencies.rb', line 170 def graphviz_image_output graphviz_data.output( :png => "#{output_file_basename}.png") end |
#output_file_basename ⇒ Object
Basename to use for output files.
159 160 161 162 |
# File 'lib/pod/command/dependencies.rb', line 159 def output_file_basename return 'Podfile' unless @podspec_name File.basename(@podspec_name, File.extname(@podspec_name)) end |
#pod_occurrences_in_podfile ⇒ Object
182 183 184 185 186 187 188 189 190 |
# File 'lib/pod/command/dependencies.rb', line 182 def pod_occurrences_in_podfile counter = 0 podfile_dependencies.each do |pod| if sanitized_pod_name(pod) == @lib_to_find counter = counter + 1 end end counter end |
#pod_occurrences_in_podfile_dependencies ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/pod/command/dependencies.rb', line 192 def pod_occurrences_in_podfile_dependencies counter = 0 pod_to_dependencies.each do |pod, dependencies| dependencies.each do |dependency| if sanitized_pod_name(dependency) == @lib_to_find counter = counter + 1 end end end counter 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.
154 155 156 |
# File 'lib/pod/command/dependencies.rb', line 154 def pod_to_dependencies dependencies.map { |d| d.is_a?(Hash) ? d : { d => [] } }.reduce({}) { |combined, individual| combined.merge!(individual) } end |
#podfile ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/pod/command/dependencies.rb', line 89 def podfile @podfile ||= begin if podspec = @podspec platform = podspec.available_platforms.first platform_name = platform.name platform_version = platform.deployment_target.to_s source_urls = Config.instance.sources_manager.all.map(&:url).compact Podfile.new do install! 'cocoapods', integrate_targets: false, warn_for_multiple_pod_sources: false source_urls.each { |u| source(u) } platform platform_name, platform_version pod podspec.name, podspec: podspec.defined_in_file target 'Dependencies' 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.
149 150 151 |
# File 'lib/pod/command/dependencies.rb', line 149 def podfile_dependencies Set.new(podfile.target_definitions.values.map { |t| t.dependencies.map { |d| d.name } }.flatten) end |
#run ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pod/command/dependencies.rb', line 61 def run require 'yaml' UI.title "Calculating dependencies" do dependencies end graphviz_image_output if @produce_image_output graphviz_dot_output if @produce_graphviz_output yaml_output UI.puts "#{@lib_to_find} occurrences: #{find_occurrences}" if @lib_to_find end |
#sandbox ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/pod/command/dependencies.rb', line 110 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.
144 145 146 |
# File 'lib/pod/command/dependencies.rb', line 144 def sanitized_pod_name(name) Pod::Dependency.from_string(name).name end |
#validate! ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pod/command/dependencies.rb', line 38 def validate! super if @podspec_name require 'pathname' path = Pathname.new(@podspec_name) if path.file? @podspec = Specification.from_file(path) else sets = Config. instance. sources_manager. search(Dependency.new(@podspec_name)) spec = sets && sets.specification @podspec = spec && spec.subspec_by_name(@podspec_name) raise Informative, "Cannot find `#{@podspec_name}`." unless @podspec 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
164 165 166 167 168 |
# File 'lib/pod/command/dependencies.rb', line 164 def yaml_output UI.title 'Dependencies' do UI.puts YAML.dump(dependencies) end end |