Class: Pod::Source
- Inherits:
-
Object
- Object
- Pod::Source
- Defined in:
- lib/cocoapods-core/source.rb,
lib/cocoapods-core/source/acceptor.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"
Defined Under Namespace
Classes: Acceptor, Aggregate, HealthReporter
Instance Attribute Summary collapse
-
#repo ⇒ Pathname
readonly
The path where the source is stored.
Queering 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.
-
#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.
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.
23 24 25 |
# File 'lib/cocoapods-core/source.rb', line 23 def initialize(repo) @repo = Pathname.new(repo) end |
Instance Attribute Details
#repo ⇒ Pathname (readonly)
Returns The path where the source is stored.
19 20 21 |
# File 'lib/cocoapods-core/source.rb', line 19 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.
62 63 64 |
# File 'lib/cocoapods-core/source.rb', line 62 def <=>(other) name <=> other.name end |
#all_specs ⇒ Array<Specification>
Returns all the specifications contained by the source.
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/cocoapods-core/source.rb', line 150 def all_specs specs = pods.map do |name| begin versions(name).map { |version| specification(name, version) } rescue CoreUI.warn "Skipping `#{name}` because the podspec contains errors." next end end specs.flatten.compact end |
#fuzzy_search(query) ⇒ Set, Nil
Returns the set of the Pod whose name fuzzily matches the given query.
249 250 251 252 253 254 255 |
# File 'lib/cocoapods-core/source.rb', line 249 def fuzzy_search(query) require 'fuzzy_match' pod_name = FuzzyMatch.new(pods).find(query) if pod_name search(pod_name) end end |
#inspect ⇒ String
Returns A description suitable for debugging.
68 69 70 |
# File 'lib/cocoapods-core/source.rb', line 68 def inspect "#<#{self.class} name:#{name} type:#{type}>" end |
#name ⇒ String Also known as: to_s
Returns The name of the source.
29 30 31 |
# File 'lib/cocoapods-core/source.rb', line 29 def name repo.basename.to_s end |
#pod_sets ⇒ Array<Sets>
Returns the sets of all the Pods.
175 176 177 |
# File 'lib/cocoapods-core/source.rb', line 175 def pod_sets pods.map { |pod_name| set(pod_name) } end |
#pods ⇒ Array<String>
Returns the list of the name of all the Pods.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cocoapods-core/source.rb', line 80 def pods unless specs_dir raise Informative, "Unable to find a source named: `#{name}`" end specs_dir_as_string = specs_dir.to_s Dir.entries(specs_dir).select do |entry| valid_name = entry[0, 1] != '.' valid_name && File.directory?(File.join(specs_dir_as_string, entry)) end.sort 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.
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/cocoapods-core/source.rb', line 192 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 if (specs_dir + query).directory? set(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.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/cocoapods-core/source.rb', line 218 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.
169 170 171 |
# File 'lib/cocoapods-core/source.rb', line 169 def set(pod_name) Specification::Set.new(pod_name, self) end |
#specification(name, version) ⇒ Specification
Returns the specification for a given version of Pod.
118 119 120 |
# File 'lib/cocoapods-core/source.rb', line 118 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.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/cocoapods-core/source.rb', line 132 def specification_path(name, version) raise ArgumentError, 'No name' unless name raise ArgumentError, 'No version' unless version path = specs_dir + 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 #{name} source." end specification_path end |
#to_hash ⇒ Hash{String=>{String=>Specification}}
Returns the static representation of all the specifications grouped first by name and then by version.
266 267 268 269 270 271 272 273 |
# File 'lib/cocoapods-core/source.rb', line 266 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.
277 278 279 280 |
# File 'lib/cocoapods-core/source.rb', line 277 def to_yaml require 'yaml' to_hash.to_yaml end |
#type ⇒ String
Returns The type of the source.
49 50 51 |
# File 'lib/cocoapods-core/source.rb', line 49 def type 'file system' end |
#url ⇒ String
Returns The URL of the source.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cocoapods-core/source.rb', line 35 def url Dir.chdir(repo) do remote = `git ls-remote --get-url`.chomp if $?.success? remote elsif (repo + '.git').exist? "file://#{repo}/.git" end end end |
#versions(name) ⇒ Array<Version>
Returns all the available versions for the Pod, sorted from highest to lowest.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cocoapods-core/source.rb', line 97 def versions(name) return nil unless specs_dir raise ArgumentError, 'No name' unless name pod_dir = specs_dir + name return unless pod_dir.exist? pod_dir.children.map do |v| basename = v.basename.to_s begin Version.new(basename) if v.directory? && basename[0, 1] != '.' rescue ArgumentError => e raise Informative, 'An unexpected version directory ' \ "`#{basename}` was encountered for the " \ "`#{pod_dir}` Pod in the `#{name}` repository." end end.compact.sort.reverse end |