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
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, Head, Presenter
Instance Attribute Summary collapse
-
#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
-
#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.
-
#specification ⇒ Specification
The top level specification of the Pod for the #required_version.
-
#specification_name ⇒ Specification
The top level specification for this set for any 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.
32 33 34 35 |
# File 'lib/cocoapods-core/specification/set.rb', line 32 def initialize(name, sources = []) @name = name @sources = Array(sources) end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the Pod.
19 20 21 |
# File 'lib/cocoapods-core/specification/set.rb', line 19 def name @name end |
#sources ⇒ Array<Source> (readonly)
Returns the sources that contain the specifications for the available versions of a Pod.
24 25 26 |
# File 'lib/cocoapods-core/specification/set.rb', line 24 def sources @sources end |
Instance Method Details
#==(other) ⇒ Object
103 104 105 106 107 |
# File 'lib/cocoapods-core/specification/set.rb', line 103 def ==(other) self.class == other.class && @name == other.name && @sources.map(&:name) == other.sources.map(&:name) end |
#highest_version ⇒ Version
Returns The highest version known of the specification.
80 81 82 |
# File 'lib/cocoapods-core/specification/set.rb', line 80 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.
90 91 92 |
# File 'lib/cocoapods-core/specification/set.rb', line 90 def highest_version_spec_path @highest_version_spec_path ||= specification_paths_for_version(highest_version).first 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.
44 45 46 47 48 49 50 51 |
# File 'lib/cocoapods-core/specification/set.rb', line 44 def specification unless highest_version_spec_path raise Informative, "Could not find the highest version for `#{name}`. "\ "This could be due to an empty #{name} directory in a local repository." end Specification.from_file(highest_version_spec_path) end |
#specification_name ⇒ Specification
Returns the top level specification for this set for any version.
55 56 57 58 59 60 61 |
# File 'lib/cocoapods-core/specification/set.rb', line 55 def specification_name versions_by_source.each do |source, versions| next unless version = versions.first return source.specification(name, version).name end nil end |
#specification_paths_for_version(version) ⇒ Array<String>
Returns the paths to specifications for the given version.
66 67 68 69 |
# File 'lib/cocoapods-core/specification/set.rb', line 66 def specification_paths_for_version(version) sources = @sources.select { |source| versions_by_source[source].include?(version) } sources.map { |source| source.specification_path(name, version) } end |
#to_hash ⇒ Hash
Returns a hash representation of the set composed by dumb data types.
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/cocoapods-core/specification/set.rb', line 125 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
109 110 111 |
# File 'lib/cocoapods-core/specification/set.rb', line 109 def to_s "#<#{self.class.name} for `#{name}' available at `#{sources.map(&:name).join(', ')}'>" end |
#versions ⇒ Array<Version>
Returns all the available versions for the Pod, sorted from highest to lowest.
74 75 76 |
# File 'lib/cocoapods-core/specification/set.rb', line 74 def versions @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.
97 98 99 100 101 |
# File 'lib/cocoapods-core/specification/set.rb', line 97 def versions_by_source @versions_by_source ||= sources.each_with_object({}) do |source, result| result[source] = source.versions(name) end end |