class Pod::Installer::PodSourceInstaller

Controller class responsible of installing the activated specifications of a single Pod.

@note This class needs to consider all the activated specs of a Pod.

Attributes

can_cache[R]

@return [Boolean] Whether the installer is allowed to touch the cache.

can_cache?[R]

@return [Boolean] Whether the installer is allowed to touch the cache.

podfile[R]

@return [Podfile] the podfile that should be integrated with the user

projects.
sandbox[R]

@return [Sandbox] The installation target.

specs_by_platform[R]

@return [Hash{Symbol=>Array}] The specifications that need to be

installed grouped by platform.

Public Class Methods

new(sandbox, podfile, specs_by_platform, can_cache: true) click to toggle source

Initialize a new instance

@param [Sandbox] sandbox @see sandbox @param [Podfile] podfile @see podfile @param [Hash{Symbol=>Array}] specs_by_platform @see specs_by_platform @param [Boolean] can_cache @see can_cache

# File lib/cocoapods/installer/pod_source_installer.rb, line 37
def initialize(sandbox, podfile, specs_by_platform, can_cache: true)
  @sandbox = sandbox
  @podfile = podfile
  @specs_by_platform = specs_by_platform
  @can_cache = can_cache
end

Public Instance Methods

clean!() click to toggle source

Cleans the installations if appropriate.

Cleaning the installation will remove any files that are not used during the build process, based on the podspec and platforms of the target that the pod is integrated into.

@see {#clean_installation}

@return [void]

# File lib/cocoapods/installer/pod_source_installer.rb, line 81
def clean!
  clean_installation unless local?
end
inspect() click to toggle source

@return [String] A string suitable for debugging.

# File lib/cocoapods/installer/pod_source_installer.rb, line 46
def inspect
  "<#{self.class} sandbox=#{sandbox.root} pod=#{root_spec.name}"
end
install!() click to toggle source

Creates the target in the Pods project and the relative support files.

@return [void]

# File lib/cocoapods/installer/pod_source_installer.rb, line 66
def install!
  download_source unless predownloaded? || local?
  PodSourcePreparer.new(root_spec, root).prepare! if local?
  sandbox.remove_local_podspec(name) unless predownloaded? || local? || external?
end
lock_files!(file_accessors) click to toggle source

Locks the source files if appropriate.

@return [void]

# File lib/cocoapods/installer/pod_source_installer.rb, line 89
def lock_files!(file_accessors)
  return if local?
  unlocked_files = source_files(file_accessors).reject { |f| (File.stat(f).mode & 0o200).zero? }
  FileUtils.chmod('u-w', unlocked_files)
end
name() click to toggle source

@return [String] The name of the pod this installer is installing.

# File lib/cocoapods/installer/pod_source_installer.rb, line 52
def name
  root_spec.name
end
unlock_files!(file_accessors) click to toggle source

Unlocks the source files if appropriate.

@return [void]

# File lib/cocoapods/installer/pod_source_installer.rb, line 99
def unlock_files!(file_accessors)
  return if local?
  FileUtils.chmod('u+w', source_files(file_accessors))
end

Private Instance Methods

clean_installation() click to toggle source

Removes all the files not needed for the installation according to the specs by platform.

@return [void]

# File lib/cocoapods/installer/pod_source_installer.rb, line 130
def clean_installation
  cleaner = Sandbox::PodDirCleaner.new(root, specs_by_platform)
  cleaner.clean!
end
download_source() click to toggle source

Downloads the source of the Pod.

@return [void]

# File lib/cocoapods/installer/pod_source_installer.rb, line 114
def download_source
  unless downloaded?
    downloader = PodSourceDownloader.new(sandbox, podfile, specs_by_platform, :can_cache => can_cache?)
    downloader.download!
  end
end
downloaded?() click to toggle source

@return [Boolean] whether the source has already been downloaded prior

to the installation process.
# File lib/cocoapods/installer/pod_source_installer.rb, line 159
def downloaded?
  sandbox.downloaded_pods.include?(root_spec.name)
end
external?() click to toggle source

@return [Boolean] whether the pod uses an external source (e.g. :podspec) in the

resolution process to retrieve its podspec.
# File lib/cocoapods/installer/pod_source_installer.rb, line 180
def external?
  @dependencies ||= podfile.dependencies.select(&:external?).map(&:name)
  @dependencies.include?(root_spec.name)
end
local?() click to toggle source

@return [Boolean] whether the pod uses the local option and thus

CocoaPods should not interfere with the files of the user.
# File lib/cocoapods/installer/pod_source_installer.rb, line 173
def local?
  sandbox.local?(root_spec.name)
end
predownloaded?() click to toggle source

@return [Boolean] whether the source has been pre downloaded in the

resolution process to retrieve its podspec.
# File lib/cocoapods/installer/pod_source_installer.rb, line 166
def predownloaded?
  sandbox.predownloaded_pods.include?(root_spec.name)
end
released?() click to toggle source
# File lib/cocoapods/installer/pod_source_installer.rb, line 185
def released?
  !local? && !predownloaded? && sandbox.specification(root_spec.name) != root_spec
end
root() click to toggle source

@return [Pathname] the folder where the source of the Pod is located.

# File lib/cocoapods/installer/pod_source_installer.rb, line 152
def root
  sandbox.pod_dir(root_spec.name)
end
root_spec() click to toggle source

@return [Specification] the root specification of the Pod.

# File lib/cocoapods/installer/pod_source_installer.rb, line 146
def root_spec
  specs.first.root
end
source_files(file_accessors) click to toggle source

@return [Array<Pathname>] The paths of the source files

# File lib/cocoapods/installer/pod_source_installer.rb, line 191
def source_files(file_accessors)
  file_accessors.flat_map(&:source_files)
end
specs() click to toggle source

@return [Array<Specifications>] the specification of the Pod used in

this installation.
# File lib/cocoapods/installer/pod_source_installer.rb, line 140
def specs
  specs_by_platform.values.flatten
end