Class: Pod::Installer::Analyzer::SandboxAnalyzer
- Inherits:
-
Object
- Object
- Pod::Installer::Analyzer::SandboxAnalyzer
- Defined in:
- lib/cocoapods/installer/analyzer/sandbox_analyzer.rb
Overview
Analyze the sandbox to detect which Pods should be removed, and which ones should be reinstalled.
The logic is the following:
Added
- If not present in the sandbox lockfile.
- The directory of the Pod doesn't exits.
Changed
- The version of the Pod changed.
- The SHA of the specification file changed.
- The specific installed (sub)specs of the same Pod changed.
- The specification is from an external source and the installation process is in update mode.
- The directory of the Pod is empty.
- The Pod has been pre-downloaded.
Removed
- If a specification is present in the lockfile but not in the resolved specs.
Unchanged
- If none of the above conditions match.
Instance Attribute Summary collapse
-
#podfile ⇒ Podfile
readonly
The Podfile to analyze dependencies.
-
#sandbox ⇒ Sandbox
readonly
The sandbox to analyze.
-
#specs ⇒ Array<Specifications>
readonly
The specifications returned by the resolver.
-
#update_mode ⇒ Boolean
(also: #update_mode?)
readonly
Whether the installation is performed in update mode.
Pod state collapse
-
#pod_added?(pod) ⇒ Boolean
private
Returns whether the Pod with the given name should be installed.
-
#pod_changed?(pod) ⇒ Boolean
private
Returns whether the Pod with the given name should be considered changed and thus should be reinstalled.
-
#pod_deleted?(pod) ⇒ Boolean
private
Returns whether the Pod with the given name should be removed from the installation.
-
#pod_state(pod) ⇒ Symbol
private
Returns the state of the Pod with the given name.
Private helpers collapse
- #folder_empty?(pod) ⇒ Boolean private
-
#folder_exist?(pod) ⇒ Boolean
private
--------------------------------------#.
-
#podfile_dependency(pod) ⇒ Dependency?
private
The dependency with the given name from the podfile.
-
#resolved_pods ⇒ Array<String>
private
The name of the resolved Pods.
-
#resolved_spec_names(pod) ⇒ Array<String>
private
The name of the resolved specifications (includes subspecs).
-
#root_spec(pod) ⇒ Specification
private
The root specification for the Pod with the given name.
-
#sandbox_checksum(pod) ⇒ String
private
The checksum of the specification of the Pod with the given name stored in the sandbox.
-
#sandbox_dependency(pod) ⇒ Dependency?
private
The dependency with the given name stored in the sandbox.
-
#sandbox_manifest ⇒ Lockfile
private
The manifest to use for the sandbox.
-
#sandbox_pods ⇒ Array<String>
private
The name of the Pods stored in the sandbox manifest.
-
#sandbox_spec_names(pod) ⇒ Array<String>
private
The name of the specifications stored in the sandbox manifest (includes subspecs).
-
#sandbox_version(pod) ⇒ Version
private
The version of Pod with the given name stored in the sandbox.
Instance Method Summary collapse
-
#analyze ⇒ void
Performs the analysis to the detect the state of the sandbox respect to the resolved specifications.
-
#initialize(sandbox, podfile, specs, update_mode) ⇒ SandboxAnalyzer
constructor
Init a new SandboxAnalyzer.
Constructor Details
#initialize(sandbox, podfile, specs, update_mode) ⇒ SandboxAnalyzer
Init a new SandboxAnalyzer
56 57 58 59 60 61 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 56 def initialize(sandbox, podfile, specs, update_mode) @sandbox = sandbox @podfile = podfile @specs = specs @update_mode = update_mode end |
Instance Attribute Details
#podfile ⇒ Podfile (readonly)
Returns The Podfile to analyze dependencies.
36 37 38 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 36 def podfile @podfile end |
#sandbox ⇒ Sandbox (readonly)
Returns The sandbox to analyze.
32 33 34 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 32 def sandbox @sandbox end |
#specs ⇒ Array<Specifications> (readonly)
Returns The specifications returned by the resolver.
41 42 43 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 41 def specs @specs end |
#update_mode ⇒ Boolean (readonly) Also known as: update_mode?
Returns Whether the installation is performed in update mode.
45 46 47 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 45 def update_mode @update_mode end |
Instance Method Details
#analyze ⇒ void
This method returns an undefined value.
Performs the analysis to the detect the state of the sandbox respect to the resolved specifications.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 68 def analyze state = SpecsState.new if sandbox_manifest all_names = (resolved_pods + sandbox_pods).uniq.sort all_names.sort.each do |name| state.add_name(name, pod_state(name)) end else state.added.merge(resolved_pods) end state end |
#folder_empty?(pod) ⇒ Boolean (private)
260 261 262 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 260 def folder_empty?(pod) Dir.glob(sandbox.pod_dir(pod) + '*').empty? end |
#folder_exist?(pod) ⇒ Boolean (private)
--------------------------------------#
256 257 258 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 256 def folder_exist?(pod) sandbox.pod_dir(pod).exist? end |
#pod_added?(pod) ⇒ Boolean (private)
A Pod whose folder doesn't exists is considered added.
Returns whether the Pod with the given name should be installed.
110 111 112 113 114 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 110 def pod_added?(pod) return true if resolved_pods.include?(pod) && !sandbox_pods.include?(pod) return true if !sandbox.local?(pod) && !folder_exist?(pod) false end |
#pod_changed?(pod) ⇒ Boolean (private)
In update mode, as there is no way to know if a remote source hash changed the Pods from external sources are always marked as changed.
A Pod whose folder is empty is considered changed.
Returns whether the Pod with the given name should be considered changed and thus should be reinstalled.
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 143 def pod_changed?(pod) spec = root_spec(pod) return true if spec.version != sandbox_version(pod) return true if spec.checksum != sandbox_checksum(pod) return true if resolved_spec_names(pod) != sandbox_spec_names(pod) podfile_dep = podfile_dependency(pod)&.tap { |dep| dep.podspec_repo = nil } return true if podfile_dep != sandbox_dependency(pod) return true if sandbox.predownloaded?(pod) return true if folder_empty?(pod) false end |
#pod_deleted?(pod) ⇒ Boolean (private)
Returns whether the Pod with the given name should be removed from the installation.
124 125 126 127 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 124 def pod_deleted?(pod) return true if !resolved_pods.include?(pod) && sandbox_pods.include?(pod) false end |
#pod_state(pod) ⇒ Symbol (private)
Returns the state of the Pod with the given name.
94 95 96 97 98 99 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 94 def pod_state(pod) return :deleted if pod_deleted?(pod) return :added if pod_added?(pod) return :changed if pod_changed?(pod) :unchanged end |
#podfile_dependency(pod) ⇒ Dependency? (private)
Returns The dependency with the given name from the podfile.
250 251 252 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 250 def podfile_dependency(pod) podfile.dependencies.find { |d| d.name == pod } end |
#resolved_pods ⇒ Array<String> (private)
Returns The name of the resolved Pods.
171 172 173 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 171 def resolved_pods @resolved_pods ||= specs.map { |spec| spec.root.name }.uniq end |
#resolved_spec_names(pod) ⇒ Array<String> (private)
Returns The name of the resolved specifications (includes subspecs).
188 189 190 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 188 def resolved_spec_names(pod) specs.select { |s| s.root.name == pod }.map(&:name).uniq.sort end |
#root_spec(pod) ⇒ Specification (private)
Returns The root specification for the Pod with the given name.
208 209 210 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 208 def root_spec(pod) specs.find { |s| s.root.name == pod }.root end |
#sandbox_checksum(pod) ⇒ String (private)
Returns The checksum of the specification of the Pod with the given name stored in the sandbox.
230 231 232 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 230 def sandbox_checksum(pod) sandbox_manifest.checksum(pod) end |
#sandbox_dependency(pod) ⇒ Dependency? (private)
Returns The dependency with the given name stored in the sandbox.
239 240 241 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 239 def sandbox_dependency(pod) sandbox_manifest.dependencies.find { |d| d.name == pod } end |
#sandbox_manifest ⇒ Lockfile (private)
Returns The manifest to use for the sandbox.
163 164 165 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 163 def sandbox_manifest sandbox.manifest end |
#sandbox_pods ⇒ Array<String> (private)
Returns The name of the Pods stored in the sandbox manifest.
178 179 180 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 178 def sandbox_pods @sandbox_pods ||= sandbox_manifest.pod_names.map { |name| Specification.root_name(name) }.uniq end |
#sandbox_spec_names(pod) ⇒ Array<String> (private)
Returns The name of the specifications stored in the sandbox manifest (includes subspecs).
198 199 200 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 198 def sandbox_spec_names(pod) sandbox_manifest.pod_names.select { |name| Specification.root_name(name) == pod }.uniq.sort end |
#sandbox_version(pod) ⇒ Version (private)
Returns The version of Pod with the given name stored in the sandbox.
220 221 222 |
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 220 def sandbox_version(pod) sandbox_manifest.version(pod) end |