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,
lib/cocoapods-core/source/github_data_provider.rb,
lib/cocoapods-core/source/abstract_data_provider.rb,
lib/cocoapods-core/source/file_system_data_provider.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: AbstractDataProvider, Acceptor, Aggregate, FileSystemDataProvider, GitHubDataProvider, HealthReporter
Instance Attribute Summary collapse
-
#data_provider ⇒ AbstractDataProvider
The data provider for this source.
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 = nil) ⇒ 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.
Constructor Details
#initialize(repo = nil) ⇒ Source
Returns a new instance of Source.
28 29 30 31 32 33 34 35 |
# File 'lib/cocoapods-core/source.rb', line 28 def initialize(repo = nil) # TODO: Temporary solution to aide the transition if repo.is_a?(String) || repo.is_a?(Pathname) @data_provider = FileSystemDataProvider.new(repo) else @data_provider = repo end end |
Instance Attribute Details
#data_provider ⇒ AbstractDataProvider
Returns the data provider for this source.
24 25 26 |
# File 'lib/cocoapods-core/source.rb', line 24 def data_provider @data_provider 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.
58 59 60 |
# File 'lib/cocoapods-core/source.rb', line 58 def <=>(other) name <=> other.name end |
#all_specs ⇒ Array<Specification>
Returns all the specifications contained by the source.
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/cocoapods-core/source.rb', line 130 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.
245 246 247 248 249 250 251 |
# File 'lib/cocoapods-core/source.rb', line 245 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.
64 65 66 |
# File 'lib/cocoapods-core/source.rb', line 64 def inspect "#<#{self.class} name:#{name} type:#{type}>" end |
#name ⇒ String Also known as: to_s
Returns The name of the source.
39 40 41 |
# File 'lib/cocoapods-core/source.rb', line 39 def name data_provider.name end |
#pod_sets ⇒ Array<Sets>
Returns the sets of all the Pods.
155 156 157 |
# File 'lib/cocoapods-core/source.rb', line 155 def pod_sets pods.map { |pod_name| set(pod_name) } end |
#pods ⇒ Array<String>
Returns the list of the name of all the Pods.
76 77 78 79 80 81 82 83 |
# File 'lib/cocoapods-core/source.rb', line 76 def pods pods = data_provider.pods unless pods raise Informative, "Unable to find the #{data_provider.type} source " \ "named: `#{data_provider.name}`" end pods end |
#search(query) ⇒ Set
Rename to #load_set
Returns a set for a given dependency. The set is identified by the name of the dependency and takes into account subspecs.
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/cocoapods-core/source.rb', line 185 def search(query) if query.is_a?(Dependency) name = query.root_name else name = query end pod_sets.find do |set| set.name == name 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.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/cocoapods-core/source.rb', line 210 def search_by_name(query, full_text_search = false) regexp_query = /#{query}/i if full_text_search if data_provider.is_a?(FileSystemDataProvider) 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 [] 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.
149 150 151 |
# File 'lib/cocoapods-core/source.rb', line 149 def set(pod_name) Specification::Set.new(pod_name, self) end |
#specification(name, version) ⇒ Specification
Returns the specification for a given version of Pod.
100 101 102 |
# File 'lib/cocoapods-core/source.rb', line 100 def specification(name, version) Specification.from_file(specification_path(name, version)) end |
#specification_path(name, version) ⇒ Pathname
Remove.
Returns the path of the specification with the given name and version.
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/cocoapods-core/source.rb', line 114 def specification_path(name, 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 spec end |
#to_hash ⇒ Hash{String=>{String=>Specification}}
Returns the static representation of all the specifications grouped first by name and then by version.
262 263 264 265 266 267 268 269 |
# File 'lib/cocoapods-core/source.rb', line 262 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.
273 274 275 276 |
# File 'lib/cocoapods-core/source.rb', line 273 def to_yaml require 'yaml' to_hash.to_yaml end |
#type ⇒ String
Returns The type of the source.
45 46 47 |
# File 'lib/cocoapods-core/source.rb', line 45 def type data_provider.type end |