Class: Pod::Command::Check
- Inherits:
-
Pod::Command
- Object
- Pod::Command
- Pod::Command::Check
- Defined in:
- lib/pod/command/check.rb
Class Method Summary collapse
Instance Method Summary collapse
- #added_result(spec_name) ⇒ Object
- #changed_development_result(spec_name, newer_files) ⇒ Object
- #changed_result(spec_name, manifest_version, locked_version) ⇒ Object
- #find_development_pods(podfile) ⇒ Object
- #find_differences(config, development_pods) ⇒ Object
-
#get_files_for_podspec(podspec_file) ⇒ Object
Returns an array of all files pointed to by the podspec.
- #get_files_newer_than_lockfile_for_podspec(config, development_pod) ⇒ Object
- #get_podspec_for_file_or_path(podspec_file_or_path) ⇒ Object
-
#initialize(argv) ⇒ Check
constructor
A new instance of Check.
- #print_results(results) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ Check
Returns a new instance of Check.
26 27 28 29 |
# File 'lib/pod/command/check.rb', line 26 def initialize(argv) @check_command_verbose = argv.flag?('verbose') super end |
Class Method Details
.options ⇒ Object
20 21 22 23 24 |
# File 'lib/pod/command/check.rb', line 20 def self. [ ['--verbose', 'Show change details.'] ].concat(super) end |
Instance Method Details
#added_result(spec_name) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/pod/command/check.rb', line 156 def added_result(spec_name) if @check_command_verbose "#{spec_name} newly added" else "+#{spec_name}" end end |
#changed_development_result(spec_name, newer_files) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/pod/command/check.rb', line 143 def changed_development_result(spec_name, newer_files) if @check_command_verbose number_files_not_shown = newer_files.length - 2 newer_files = newer_files[0..1] if number_files_not_shown > 0 newer_files.push("and #{number_files_not_shown} other#{'s' if number_files_not_shown > 1}") end "#{spec_name} (#{newer_files.join(', ')})" else "~#{spec_name}" end end |
#changed_result(spec_name, manifest_version, locked_version) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/pod/command/check.rb', line 135 def changed_result(spec_name, manifest_version, locked_version) if @check_command_verbose "#{spec_name} #{manifest_version} -> #{locked_version}" else "~#{spec_name}" end end |
#find_development_pods(podfile) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pod/command/check.rb', line 41 def find_development_pods(podfile) development_pods = {} podfile.dependencies.each do |dependency| if dependency.local? development_pods[dependency.name] = dependency.external_source.clone development_pods[dependency.name][:path] = File.absolute_path(development_pods[dependency.name][:path]) end end development_pods end |
#find_differences(config, development_pods) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pod/command/check.rb', line 52 def find_differences(config, development_pods) all_pod_names = config.lockfile.pod_names all_pod_names.concat development_pods.keys all_pod_names.sort.uniq.map do |spec_name| locked_version = config.lockfile.version(spec_name) # If no manifest, assume Pod hasn't been installed if config.sandbox.manifest manifest_version = config.sandbox.manifest.version(spec_name) else manifest_version = nil end # If this Pod is installed if manifest_version # If this is a development pod do a modified time check if development_pods[spec_name] != nil newer_files = get_files_newer_than_lockfile_for_podspec(config, development_pods[spec_name]) if newer_files.any? changed_development_result(spec_name, newer_files) end # Otherwise just compare versions elsif locked_version != manifest_version changed_result(spec_name, manifest_version, locked_version) end # If this Pod is not installed else added_result(spec_name) end end.compact end |
#get_files_for_podspec(podspec_file) ⇒ Object
Returns an array of all files pointed to by the podspec
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/pod/command/check.rb', line 98 def get_files_for_podspec(podspec_file) podspec_file = get_podspec_for_file_or_path(podspec_file) development_pod_dir = File.dirname(podspec_file) spec = Specification.from_file(podspec_file) # Gather all the dependencies used by the spec, across all platforms, and including subspecs. all_files = [spec, spec.subspecs].flatten.map { |a_spec| a_spec.available_platforms.map { |platform| accessor = Sandbox::FileAccessor.new(Sandbox::PathList.new(Pathname.new(development_pod_dir)), a_spec.consumer(platform)) [ accessor.vendored_frameworks, accessor.vendored_libraries, accessor.resource_bundle_files, accessor.license, accessor.prefix_header, accessor.preserve_paths, accessor.readme, accessor.resources, accessor.source_files ].compact } }.flatten # Include the podspec files as well all_files.push(podspec_file) end |
#get_files_newer_than_lockfile_for_podspec(config, development_pod) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pod/command/check.rb', line 86 def get_files_newer_than_lockfile_for_podspec(config, development_pod) files_for_podspec = get_files_for_podspec(development_pod[:path]) lockfile_mtime = File.mtime(config.lockfile.defined_in_file) podspec_file = get_podspec_for_file_or_path(development_pod[:path]) podspec_dir = Pathname.new(File.dirname(podspec_file)) files_for_podspec .select {|f| File.mtime(f) >= lockfile_mtime} .map {|f| Pathname.new(f).relative_path_from(podspec_dir).to_s} end |
#get_podspec_for_file_or_path(podspec_file_or_path) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/pod/command/check.rb', line 126 def get_podspec_for_file_or_path(podspec_file_or_path) if File.basename(podspec_file_or_path).include?('.podspec') podspec_file_or_path else glob_pattern = podspec_file_or_path + '/*.podspec{,.json}' Pathname.glob(glob_pattern).first end end |
#print_results(results) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/pod/command/check.rb', line 164 def print_results(results) return UI.puts "The Podfile's dependencies are satisfied" if results.empty? if @check_command_verbose UI.puts results.join("\n") else UI.puts results.join(', ') end raise Informative, "`pod install` will install #{results.length} Pod#{'s' if results.length > 1}." end |
#run ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/pod/command/check.rb', line 31 def run unless config.lockfile raise Informative, 'Missing Podfile.lock!' end development_pods = find_development_pods(config.podfile) results = find_differences(config, development_pods) print_results(results) end |