class Pod::Installer::Analyzer::SandboxAnalyzer

Analyze the sandbox to detect which Pods should be removed, and which ones should be reinstalled.

The logic is the following:

Added

Changed

Removed

Unchanged

Attributes

podfile[R]

@return [Podfile] The Podfile to analyze dependencies.

sandbox[R]

@return [Sandbox] The sandbox to analyze.

specs[R]

@return [Array<Specifications>] The specifications returned by the

resolver.
update_mode[R]

@return [Bool] Whether the installation is performed in update mode.

update_mode?[R]

@return [Bool] Whether the installation is performed in update mode.

Public Class Methods

new(sandbox, podfile, specs, update_mode) click to toggle source

Init a new SandboxAnalyzer

@param [Sandbox] sandbox @see sandbox @param [Podfile] podfile @see podfile @param [Array<Specifications>] specs @see specs @param [Bool] update_mode @see update_mode

# 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

Public Instance Methods

analyze() click to toggle source

Performs the analysis to the detect the state of the sandbox respect to the resolved specifications.

@return [void]

# 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

Private Instance Methods

folder_empty?(pod) click to toggle source
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 259
def folder_empty?(pod)
  Dir.glob(sandbox.pod_dir(pod) + '*').empty?
end
folder_exist?(pod) click to toggle source
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 255
def folder_exist?(pod)
  sandbox.pod_dir(pod).exist?
end
pod_added?(pod) click to toggle source

Returns whether the Pod with the given name should be installed.

@note A Pod whose folder doesn't exists is considered added.

@param [String] pod

the name of the Pod.

@return [Bool] Whether the Pod is added.

# 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) click to toggle source

Returns whether the Pod with the given name should be considered changed and thus should be reinstalled.

@note 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.

@note A Pod whose folder is empty is considered changed.

@param [String] pod

the name of the Pod.

@return [Bool] Whether the Pod is changed.

# 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)
  return true if podfile_dependency(pod) != sandbox_dependency(pod)
  return true if sandbox.predownloaded?(pod)
  return true if folder_empty?(pod)
  false
end
pod_deleted?(pod) click to toggle source

Returns whether the Pod with the given name should be removed from the installation.

@param [String] pod

the name of the Pod.

@return [Bool] Whether the Pod is deleted.

# 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) click to toggle source

Returns the state of the Pod with the given name.

@param [String] pod

the name of the Pod.

@return [Symbol] The state

# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 94
def pod_state(pod)
  return :added   if pod_added?(pod)
  return :deleted if pod_deleted?(pod)
  return :changed if pod_changed?(pod)
  :unchanged
end
podfile_dependency(pod) click to toggle source

@return [Dependency, nil] The dependency with the given name from the podfile.

@param [String] pod

the name of the Pod.
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 249
def podfile_dependency(pod)
  podfile.dependencies.find { |d| d.name == pod }
end
resolved_pods() click to toggle source

@return [Array<String>] The name of the resolved Pods.

# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 170
def resolved_pods
  @resolved_pods ||= specs.map { |spec| spec.root.name }.uniq
end
resolved_spec_names(pod) click to toggle source

@return [Array<String>] The name of the resolved specifications

(includes subspecs).

@param [String] pod

the name of the Pod.
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 187
def resolved_spec_names(pod)
  specs.select { |s| s.root.name == pod }.map(&:name).uniq.sort
end
root_spec(pod) click to toggle source

@return [Specification] The root specification for the Pod with the

given name.

@param [String] pod

the name of the Pod.
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 207
def root_spec(pod)
  specs.find { |s| s.root.name == pod }.root
end
sandbox_checksum(pod) click to toggle source

@return [String] The checksum of the specification of the Pod with

the given name stored in the sandbox.

@param [String] pod

the name of the Pod.
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 229
def sandbox_checksum(pod)
  sandbox_manifest.checksum(pod)
end
sandbox_dependency(pod) click to toggle source

@return [Dependency, nil] The dependency with the given name stored in the sandbox.

@param [String] pod

the name of the Pod.
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 238
def sandbox_dependency(pod)
  sandbox_manifest.dependencies.find { |d| d.name == pod }
end
sandbox_manifest() click to toggle source

@return [Lockfile] The manifest to use for the sandbox.

# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 162
def sandbox_manifest
  sandbox.manifest
end
sandbox_pods() click to toggle source

@return [Array<String>] The name of the Pods stored in the sandbox

manifest.
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 177
def sandbox_pods
  @sandbox_pods ||= sandbox_manifest.pod_names.map { |name| Specification.root_name(name) }.uniq
end
sandbox_spec_names(pod) click to toggle source

@return [Array<String>] The name of the specifications stored in the

sandbox manifest (includes subspecs).

@param [String] pod

the name of the Pod.
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 197
def sandbox_spec_names(pod)
  sandbox_manifest.pod_names.select { |name| Specification.root_name(name) == pod }.uniq.sort
end
sandbox_version(pod) click to toggle source

@return [Version] The version of Pod with the given name stored in

the sandbox.

@param [String] pod

the name of the Pod.
# File lib/cocoapods/installer/analyzer/sandbox_analyzer.rb, line 219
def sandbox_version(pod)
  sandbox_manifest.version(pod)
end