Class: Pod::Source
- Inherits:
-
Object
- Object
- Pod::Source
- Defined in:
- lib/cocoapods-core/source.rb,
lib/cocoapods-core/source/manager.rb,
lib/cocoapods-core/source/acceptor.rb,
lib/cocoapods-core/source/metadata.rb,
lib/cocoapods-core/source/aggregate.rb,
lib/cocoapods-core/source/health_reporter.rb
Overview
The Source class is responsible to manage a collection of podspecs.
The backing store of the podspecs collection is an implementation detail abstracted from the rest of CocoaPods.
The default implementation uses a git repo as a backing store, where the podspecs are namespaced as:
"#{SPEC_NAME}/#{VERSION}/#{SPEC_NAME}.podspec"
Direct Known Subclasses
Defined Under Namespace
Classes: Acceptor, Aggregate, HealthReporter, Manager, Metadata
Paths collapse
-
#repo ⇒ Pathname
readonly
The path where the source is stored.
Instance Attribute Summary collapse
-
#metadata ⇒ Pod::Source::Metadata
readonly
The metadata for this source.
Paths collapse
-
#metadata_path ⇒ Pathname
The path at which source metadata is stored.
-
#pod_path(name) ⇒ Pathname
The path at which the specs for the given pod are stored.
-
#specs_dir ⇒ Pathname
The directory where the specs are stored.
Querying the source collapse
-
#all_specs ⇒ Array<Specification>
All the specifications contained by the source.
-
#pod_sets ⇒ Array<Sets>
The sets of all the Pods.
-
#pods ⇒ Array<String>
The list of the name of all the Pods.
-
#pods_for_specification_paths(spec_paths) ⇒ Array<String>
Returns pod names for given array of specification paths.
-
#set(pod_name) ⇒ Sets
Returns the set for the Pod with the given name.
-
#specification(name, version) ⇒ Specification
The specification for a given version of Pod.
-
#specification_path(name, version) ⇒ Pathname
Returns the path of the specification with the given name and version.
-
#versions(name) ⇒ Array<Version>
All the available versions for the Pod, sorted from highest to lowest.
Searching the source collapse
-
#fuzzy_search(query) ⇒ Set, Nil
Returns the set of the Pod whose name fuzzily matches the given query.
-
#search(query) ⇒ Set
A set for a given dependency.
-
#search_by_name(query, full_text_search = false) ⇒ Array<Set>
The list of the sets that contain the search term.
Updating the source collapse
- #git? ⇒ Boolean
-
#update(show_output) ⇒ Array<String>
Updates the local clone of the source repo.
- #verify_compatibility! ⇒ Object
Representations collapse
-
#to_hash ⇒ Hash{String=>{String=>Specification}}
The static representation of all the specifications grouped first by name and then by version.
-
#to_yaml ⇒ String
The YAML encoded #to_hash representation.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compares a source with another one for sorting purposes.
-
#initialize(repo) ⇒ Source
constructor
A new instance of Source.
-
#inspect ⇒ String
A description suitable for debugging.
-
#name ⇒ String
(also: #to_s)
The name of the source.
-
#type ⇒ String
The type of the source.
-
#url ⇒ String
The URL of the source.
Constructor Details
#initialize(repo) ⇒ Source
Returns a new instance of Source.
25 26 27 28 29 |
# File 'lib/cocoapods-core/source.rb', line 25 def initialize(repo) @repo = Pathname(repo). @versions_by_name = {} end |
Instance Attribute Details
#metadata ⇒ Pod::Source::Metadata (readonly)
Returns The metadata for this source.
21 22 23 |
# File 'lib/cocoapods-core/source.rb', line 21 def @metadata end |
#repo ⇒ Pathname (readonly)
Returns The path where the source is stored.
85 86 87 |
# File 'lib/cocoapods-core/source.rb', line 85 def repo @repo end |
Instance Method Details
#<=>(other) ⇒ Integer
Source are compared by the alphabetical order of their name, and this convention should be used in any case where sources need to be disambiguated.
Returns compares a source with another one for sorting purposes.
70 71 72 |
# File 'lib/cocoapods-core/source.rb', line 70 def <=>(other) name <=> other.name end |
#all_specs ⇒ Array<Specification>
Returns all the specifications contained by the source.
214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/cocoapods-core/source.rb', line 214 def all_specs glob = specs_dir.join('*/' * .prefix_lengths.size, '*', '*', '*.podspec{.json,}') specs = Pathname.glob(glob).map do |path| begin Specification.from_file(path) rescue CoreUI.warn "Skipping `#{path.relative_path_from(repo)}` because the " \ 'podspec contains errors.' next end end specs.compact end |
#fuzzy_search(query) ⇒ Set, Nil
Returns the set of the Pod whose name fuzzily matches the given query.
323 324 325 326 327 328 329 |
# File 'lib/cocoapods-core/source.rb', line 323 def fuzzy_search(query) require 'fuzzy_match' pod_name = FuzzyMatch.new(pods).find(query) if pod_name search(pod_name) end end |
#git? ⇒ Boolean
356 357 358 |
# File 'lib/cocoapods-core/source.rb', line 356 def git? !repo_git(%w(rev-parse HEAD)).empty? end |
#inspect ⇒ String
Returns A description suitable for debugging.
76 77 78 |
# File 'lib/cocoapods-core/source.rb', line 76 def inspect "#<#{self.class} name:#{name} type:#{type}>" end |
#metadata_path ⇒ Pathname
Returns The path at which source metadata is stored.
116 117 118 |
# File 'lib/cocoapods-core/source.rb', line 116 def repo + 'CocoaPods-version.yml' end |
#name ⇒ String Also known as: to_s
Returns The name of the source.
33 34 35 |
# File 'lib/cocoapods-core/source.rb', line 33 def name repo.basename.to_s end |
#pod_path(name) ⇒ Pathname
Returns The path at which the specs for the given pod are stored.
110 111 112 |
# File 'lib/cocoapods-core/source.rb', line 110 def pod_path(name) specs_dir.join(*.path_fragment(name)) end |
#pod_sets ⇒ Array<Sets>
Returns the sets of all the Pods.
241 242 243 |
# File 'lib/cocoapods-core/source.rb', line 241 def pod_sets pods.map { |pod_name| set(pod_name) } end |
#pods ⇒ Array<String>
Returns the list of the name of all the Pods.
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/cocoapods-core/source.rb', line 128 def pods unless specs_dir raise Informative, "Unable to find a source named: `#{name}`" end glob = specs_dir.join('*/' * .prefix_lengths.size, '*') Pathname.glob(glob).reduce([]) do |pods, entry| pods << entry.basename.to_s if entry.directory? pods end.sort end |
#pods_for_specification_paths(spec_paths) ⇒ Array<String>
Returns pod names for given array of specification paths.
146 147 148 149 150 151 152 153 |
# File 'lib/cocoapods-core/source.rb', line 146 def pods_for_specification_paths(spec_paths) spec_paths.map do |path| absolute_path = repo + path relative_path = absolute_path.relative_path_from(specs_dir) # The first file name returned by 'each_filename' is the pod name relative_path.each_filename.first end end |
#search(query) ⇒ Set
Rename to #load_set
This method is optimized for fast lookups by name, i.e. it does not require iterating through #pod_sets
Returns a set for a given dependency. The set is identified by the name of the dependency and takes into account subspecs.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/cocoapods-core/source.rb', line 258 def search(query) unless specs_dir raise Informative, "Unable to find a source named: `#{name}`" end if query.is_a?(Dependency) query = query.root_name end found = [] Pathname.glob(pod_path(query)) do |path| next unless Dir.foreach(path).any? { |child| child != '.' && child != '..' } found << path.basename.to_s end if [query] == found set = set(query) set if set.specification_name == query end end |
#search_by_name(query, full_text_search = false) ⇒ Array<Set>
Rename to #search
full text search requires to load the specification for each pod, hence is considerably slower.
Returns The list of the sets that contain the search term.
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/cocoapods-core/source.rb', line 292 def search_by_name(query, full_text_search = false) regexp_query = /#{query}/i if full_text_search pod_sets.reject do |set| texts = [] begin s = set.specification texts << s.name texts += s..keys texts << s.summary texts << s.description rescue CoreUI.warn "Skipping `#{set.name}` because the podspec " \ 'contains errors.' end texts.grep(regexp_query).empty? end else names = pods.grep(regexp_query) names.map { |pod_name| set(pod_name) } end end |
#set(pod_name) ⇒ Sets
Returns the set for the Pod with the given name.
235 236 237 |
# File 'lib/cocoapods-core/source.rb', line 235 def set(pod_name) Specification::Set.new(pod_name, self) end |
#specification(name, version) ⇒ Specification
Returns the specification for a given version of Pod.
182 183 184 |
# File 'lib/cocoapods-core/source.rb', line 182 def specification(name, version) Specification.from_file(specification_path(name, version)) end |
#specification_path(name, version) ⇒ Pathname
Returns the path of the specification with the given name and version.
196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/cocoapods-core/source.rb', line 196 def specification_path(name, version) raise ArgumentError, 'No name' unless name raise ArgumentError, 'No version' unless version path = pod_path(name) + version.to_s specification_path = path + "#{name}.podspec.json" unless specification_path.exist? specification_path = path + "#{name}.podspec" end unless specification_path.exist? raise StandardError, "Unable to find the specification #{name} " \ "(#{version}) in the #{self.name} source." end specification_path end |
#specs_dir ⇒ Pathname
In previous versions of CocoaPods they used to be stored in the root of the repo. This lead to issues, especially with the GitHub interface and now they are stored in a dedicated folder.
Returns The directory where the specs are stored.
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cocoapods-core/source.rb', line 94 def specs_dir @specs_dir ||= begin specs_sub_dir = repo + 'Specs' if specs_sub_dir.exist? specs_sub_dir elsif repo.exist? repo end end end |
#to_hash ⇒ Hash{String=>{String=>Specification}}
Returns the static representation of all the specifications grouped first by name and then by version.
382 383 384 385 386 387 388 389 |
# File 'lib/cocoapods-core/source.rb', line 382 def to_hash hash = {} all_specs.each do |spec| hash[spec.name] ||= {} hash[spec.name][spec.version.version] = spec.to_hash end hash end |
#to_yaml ⇒ String
Returns the YAML encoded #to_hash representation.
393 394 395 396 |
# File 'lib/cocoapods-core/source.rb', line 393 def to_yaml require 'yaml' to_hash.to_yaml end |
#type ⇒ String
Returns The type of the source.
57 58 59 |
# File 'lib/cocoapods-core/source.rb', line 57 def type 'file system' end |
#update(show_output) ⇒ Array<String>
Updates the local clone of the source repo.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/cocoapods-core/source.rb', line 341 def update(show_output) return [] if unchanged_github_repo? prev_commit_hash = git_commit_hash update_git_repo(show_output) @versions_by_name.clear if version = .last_compatible_version(Version.new(CORE_VERSION)) tag = "v#{version}" CoreUI.warn "Using the `#{tag}` tag of the `#{name}` source because " \ "it is the last version compatible with CocoaPods #{CORE_VERSION}." repo_git(['checkout', tag]) end diff_until_commit_hash(prev_commit_hash) end |
#url ⇒ String
In the past we had used ‘git ls-remote –get-url`, but this could lead to an issue when finding a source based on its URL when `git` is configured to rewrite URLs with the `url.<base>.insteadOf` option. See github.com/CocoaPods/CocoaPods/issues/2724.
Returns The URL of the source.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cocoapods-core/source.rb', line 44 def url @url ||= begin remote = repo_git(%w(config --get remote.origin.url)) if !remote.empty? remote elsif (repo + '.git').exist? "file://#{repo}/.git" end end end |
#verify_compatibility! ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/cocoapods-core/source.rb', line 360 def verify_compatibility! return if .compatible?(CORE_VERSION) version_msg = if .minimum_cocoapods_version == .maximum_cocoapods_version .minimum_cocoapods_version else "#{.minimum_cocoapods_version} - #{.maximum_cocoapods_version}" end raise Informative, "The `#{name}` repo requires " \ "CocoaPods #{version_msg} (currently using #{CORE_VERSION})\n" \ 'Update CocoaPods, or checkout the appropriate tag in the repo.' end |
#versions(name) ⇒ Array<Version>
Returns all the available versions for the Pod, sorted from highest to lowest.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/cocoapods-core/source.rb', line 161 def versions(name) return nil unless specs_dir raise ArgumentError, 'No name' unless name pod_dir = pod_path(name) return unless pod_dir.exist? @versions_by_name[name] ||= pod_dir.children.map do |v| basename = v.basename.to_s begin Version.new(basename) if v.directory? && basename[0, 1] != '.' rescue ArgumentError raise Informative, 'An unexpected version directory ' \ "`#{basename}` was encountered for the " \ "`#{pod_dir}` Pod in the `#{name}` repository." end end.compact.sort.reverse end |