Class: Pod::Installer::PodSourceInstaller
- Inherits:
-
Object
- Object
- Pod::Installer::PodSourceInstaller
- Defined in:
- lib/cocoapods/installer/pod_source_installer.rb
Overview
This class needs to consider all the activated specs of a Pod.
Controller class responsible of installing the activated specifications of a single Pod.
Instance Attribute Summary collapse
-
#can_cache ⇒ Boolean
(also: #can_cache?)
readonly
Whether the installer is allowed to touch the cache.
-
#podfile ⇒ Podfile
readonly
The podfile that should be integrated with the user projects.
-
#sandbox ⇒ Sandbox
readonly
The installation target.
-
#specs_by_platform ⇒ Hash{Symbol=>Array}
readonly
The specifications that need to be installed grouped by platform.
Installation collapse
-
#clean! ⇒ void
Cleans the installations if appropriate.
-
#install! ⇒ void
Creates the target in the Pods project and the relative support files.
-
#lock_files!(file_accessors) ⇒ void
Locks the source files if appropriate.
-
#unlock_files!(file_accessors) ⇒ void
Unlocks the source files if appropriate.
Installation Steps collapse
-
#clean_installation ⇒ void
private
Removes all the files not needed for the installation according to the specs by platform.
-
#download_source ⇒ void
private
Downloads the source of the Pod.
Convenience methods. collapse
-
#downloaded? ⇒ Boolean
private
Whether the source has already been downloaded prior to the installation process.
-
#external? ⇒ Boolean
private
Whether the pod uses an external source (e.g. :podspec) in the resolution process to retrieve its podspec.
-
#local? ⇒ Boolean
private
Whether the pod uses the local option and thus CocoaPods should not interfere with the files of the user.
-
#predownloaded? ⇒ Boolean
private
Whether the source has been pre downloaded in the resolution process to retrieve its podspec.
- #released? ⇒ Boolean private
-
#root ⇒ Pathname
private
The folder where the source of the Pod is located.
-
#root_spec ⇒ Specification
private
The root specification of the Pod.
-
#source_files(file_accessors) ⇒ Array<Pathname>
private
The paths of the source files.
-
#specs ⇒ Array<Specifications>
private
The specification of the Pod used in this installation.
Instance Method Summary collapse
-
#initialize(sandbox, podfile, specs_by_platform, can_cache: true) ⇒ PodSourceInstaller
constructor
Initialize a new instance.
-
#inspect ⇒ String
A string suitable for debugging.
-
#name ⇒ String
The name of the pod this installer is installing.
Constructor Details
#initialize(sandbox, podfile, specs_by_platform, can_cache: true) ⇒ PodSourceInstaller
Initialize a new instance
37 38 39 40 41 42 |
# 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 |
Instance Attribute Details
#can_cache ⇒ Boolean (readonly) Also known as: can_cache?
Returns Whether the installer is allowed to touch the cache.
27 28 29 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 27 def can_cache @can_cache end |
#podfile ⇒ Podfile (readonly)
Returns the podfile that should be integrated with the user projects.
18 19 20 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 18 def podfile @podfile end |
#sandbox ⇒ Sandbox (readonly)
Returns The installation target.
13 14 15 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 13 def sandbox @sandbox end |
#specs_by_platform ⇒ Hash{Symbol=>Array} (readonly)
Returns The specifications that need to be installed grouped by platform.
23 24 25 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 23 def specs_by_platform @specs_by_platform end |
Instance Method Details
#clean! ⇒ void
This method returns an undefined value.
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.
81 82 83 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 81 def clean! clean_installation unless local? end |
#clean_installation ⇒ void (private)
This method returns an undefined value.
Removes all the files not needed for the installation according to the specs by platform.
130 131 132 133 |
# 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 ⇒ void (private)
This method returns an undefined value.
Downloads the source of the Pod.
114 115 116 117 118 119 |
# 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? ⇒ Boolean (private)
Returns whether the source has already been downloaded prior to the installation process.
159 160 161 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 159 def downloaded? sandbox.downloaded_pods.include?(root_spec.name) end |
#external? ⇒ Boolean (private)
Returns whether the pod uses an external source (e.g. :podspec) in the resolution process to retrieve its podspec.
180 181 182 183 |
# 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 |
#inspect ⇒ String
Returns A string suitable for debugging.
46 47 48 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 46 def inspect "<#{self.class} sandbox=#{sandbox.root} pod=#{root_spec.name}" end |
#install! ⇒ void
This method returns an undefined value.
Creates the target in the Pods project and the relative support files.
66 67 68 69 70 |
# 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 |
#local? ⇒ Boolean (private)
Returns whether the pod uses the local option and thus CocoaPods should not interfere with the files of the user.
173 174 175 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 173 def local? sandbox.local?(root_spec.name) end |
#lock_files!(file_accessors) ⇒ void
This method returns an undefined value.
Locks the source files if appropriate.
89 90 91 92 93 |
# 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 ⇒ String
Returns The name of the pod this installer is installing.
52 53 54 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 52 def name root_spec.name end |
#predownloaded? ⇒ Boolean (private)
Returns whether the source has been pre downloaded in the resolution process to retrieve its podspec.
166 167 168 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 166 def predownloaded? sandbox.predownloaded_pods.include?(root_spec.name) end |
#released? ⇒ Boolean (private)
185 186 187 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 185 def released? !local? && !predownloaded? && sandbox.specification(root_spec.name) != root_spec end |
#root ⇒ Pathname (private)
Returns the folder where the source of the Pod is located.
152 153 154 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 152 def root sandbox.pod_dir(root_spec.name) end |
#root_spec ⇒ Specification (private)
Returns the root specification of the Pod.
146 147 148 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 146 def root_spec specs.first.root end |
#source_files(file_accessors) ⇒ Array<Pathname> (private)
Returns The paths of the source files.
191 192 193 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 191 def source_files(file_accessors) file_accessors.flat_map(&:source_files) end |
#specs ⇒ Array<Specifications> (private)
Returns the specification of the Pod used in this installation.
140 141 142 |
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 140 def specs specs_by_platform.values.flatten end |
#unlock_files!(file_accessors) ⇒ void
This method returns an undefined value.
Unlocks the source files if appropriate.
99 100 101 102 |
# 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 |