Class: Pod::Specification::Set
- Inherits:
-
Object
- Object
- Pod::Specification::Set
- Defined in:
- lib/cocoapods-core/specification/set.rb,
lib/cocoapods-core/specification/set/presenter.rb,
lib/cocoapods-core/specification/set/statistics.rb
Overview
The order in which the sets are provided is used to select a specification if multiple are available for a given version.
The set class is not and should be not aware of the backing store of a Source.
A Specification::Set is responsible of handling all the specifications of a Pod. This class stores the information of the dependencies that required a Pod in the resolution process.
Direct Known Subclasses
Defined Under Namespace
Classes: External, Presenter, Statistics
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#dependencies_by_requirer_name ⇒ Object
———————————————————————–#.
-
#name ⇒ String
readonly
The name of the Pod.
-
#sources ⇒ Array<Source>
readonly
The sources that contain the specifications for the available versions of a Pod.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#acceptable_versions ⇒ Array<Version>
All the versions which are acceptable given the requirements.
-
#dependency ⇒ Dependency
A dependency that includes all the versions requirements of the stored dependencies.
-
#highest_version ⇒ Version
The highest version known of the specification.
-
#highest_version_spec_path ⇒ Pathname
The path of the highest version.
-
#initialize(name, sources = []) ⇒ Set
constructor
A new instance of Set.
-
#required_by(dependency, dependent_name) ⇒ void
Stores a dependency on the Pod.
-
#required_version ⇒ Version
The highest version that satisfies the stored dependencies.
-
#specification ⇒ Specification
The top level specification of the Pod for the #required_version.
-
#specification_paths_for_version(_version) ⇒ Array<String>
The paths to specifications for the given version.
-
#to_hash ⇒ Hash
Returns a hash representation of the set composed by dumb data types.
- #to_s ⇒ Object (also: #inspect)
-
#versions ⇒ Array<Version>
All the available versions for the Pod, sorted from highest to lowest.
-
#versions_by_source ⇒ Hash{Source => Version}
All the available versions for the Pod grouped by source.
Constructor Details
#initialize(name, sources = []) ⇒ Set
Returns a new instance of Set.
33 34 35 36 37 38 |
# File 'lib/cocoapods-core/specification/set.rb', line 33 def initialize(name, sources = []) @name = name @sources = Array(sources) @dependencies_by_requirer_name = {} @dependencies = [] end |
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
196 197 198 |
# File 'lib/cocoapods-core/specification/set.rb', line 196 def dependencies @dependencies end |
#dependencies_by_requirer_name ⇒ Object
———————————————————————–#
195 196 197 |
# File 'lib/cocoapods-core/specification/set.rb', line 195 def dependencies_by_requirer_name @dependencies_by_requirer_name end |
#name ⇒ String (readonly)
Returns the name of the Pod.
20 21 22 |
# File 'lib/cocoapods-core/specification/set.rb', line 20 def name @name end |
#sources ⇒ Array<Source> (readonly)
Returns the sources that contain the specifications for the available versions of a Pod.
25 26 27 |
# File 'lib/cocoapods-core/specification/set.rb', line 25 def sources @sources end |
Instance Method Details
#==(other) ⇒ Object
157 158 159 160 161 |
# File 'lib/cocoapods-core/specification/set.rb', line 157 def ==(other) self.class == other.class && @name == other.name && @sources.map(&:name) == other.sources.map(&:name) end |
#acceptable_versions ⇒ Array<Version>
Returns All the versions which are acceptable given the requirements.
119 120 121 |
# File 'lib/cocoapods-core/specification/set.rb', line 119 def acceptable_versions versions.select { |v| dependency.match?(name, v) } end |
#dependency ⇒ Dependency
Returns A dependency that includes all the versions requirements of the stored dependencies.
76 77 78 79 80 |
# File 'lib/cocoapods-core/specification/set.rb', line 76 def dependency dependencies.reduce(Dependency.new(name)) do |previous, dependency| previous.merge(dependency.to_root_dependency) end end |
#highest_version ⇒ Version
Returns The highest version known of the specification.
132 133 134 |
# File 'lib/cocoapods-core/specification/set.rb', line 132 def highest_version versions.first end |
#highest_version_spec_path ⇒ Pathname
If multiple sources have a specification for the #required_version, the order in which they are provided is used to disambiguate.
Returns The path of the highest version.
142 143 144 |
# File 'lib/cocoapods-core/specification/set.rb', line 142 def highest_version_spec_path specification_paths_for_version(highest_version).first end |
#required_by(dependency, dependent_name) ⇒ void
This should simply return a boolean. Is CocoaPods that should raise.
This method returns an undefined value.
Stores a dependency on the Pod.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cocoapods-core/specification/set.rb', line 57 def required_by(dependency, dependent_name) dependencies_by_requirer_name[dependent_name] ||= [] dependencies_by_requirer_name[dependent_name] << dependency dependencies << dependency if acceptable_versions.empty? = "Unable to satisfy the following requirements:\n\n" dependencies_by_requirer_name.each do |name, dependencies| dependencies.each do |dep| << "- `#{dep}` required by `#{name}`\n" end end raise Informative, end end |
#required_version ⇒ Version
This should simply return nil. CocoaPods should raise instead.
Returns the highest version that satisfies the stored dependencies.
107 108 109 110 111 112 113 114 |
# File 'lib/cocoapods-core/specification/set.rb', line 107 def required_version version = versions.find { |v| dependency.match?(name, v) } unless version raise Informative, "Required version (#{dependency}) not found " \ "for `#{name}`.\nAvailable versions: #{versions.join(', ')}" end version end |
#specification ⇒ Specification
If multiple sources have a specification for the #required_version, the order in which they are provided is used to disambiguate.
Returns the top level specification of the Pod for the #required_version.
89 90 91 92 |
# File 'lib/cocoapods-core/specification/set.rb', line 89 def specification path = specification_paths_for_version(required_version).first Specification.from_file(path) end |
#specification_paths_for_version(_version) ⇒ Array<String>
Returns the paths to specifications for the given version.
97 98 99 100 |
# File 'lib/cocoapods-core/specification/set.rb', line 97 def specification_paths_for_version(_version) sources = @sources.select { |source| versions_by_source[source].include?(required_version) } sources.map { |source| source.specification_path(name, required_version) } end |
#to_hash ⇒ Hash
Returns a hash representation of the set composed by dumb data types.
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/cocoapods-core/specification/set.rb', line 180 def to_hash versions = versions_by_source.reduce({}) do |memo, (source, version)| memo[source.name] = version.map(&:to_s) memo end { 'name' => name, 'versions' => versions, 'highest_version' => highest_version.to_s, 'highest_version_spec' => highest_version_spec_path.to_s, } end |
#to_s ⇒ Object Also known as: inspect
163 164 165 166 |
# File 'lib/cocoapods-core/specification/set.rb', line 163 def to_s "#<#{self.class.name} for `#{name}' with required version " \ "`#{required_version}' available at `#{sources.map(&:name) * ', '}'>" end |
#versions ⇒ Array<Version>
Returns all the available versions for the Pod, sorted from highest to lowest.
126 127 128 |
# File 'lib/cocoapods-core/specification/set.rb', line 126 def versions versions_by_source.values.flatten.uniq.sort.reverse end |
#versions_by_source ⇒ Hash{Source => Version}
Returns all the available versions for the Pod grouped by source.
149 150 151 152 153 154 155 |
# File 'lib/cocoapods-core/specification/set.rb', line 149 def versions_by_source result = {} sources.each do |source| result[source] = source.versions(name) end result end |