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 alphabetical order of the sets 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
-
#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
-
#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_path_for_version(version) ⇒ Object
-
#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.
37 38 39 40 41 42 43 |
# File 'lib/cocoapods-core/specification/set.rb', line 37 def initialize(name, sources = []) @name = name sources = sources.is_a?(Array) ? sources : [sources] @sources = sources.sort_by(&:name) @required_by = [] @dependencies = [] end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the Pod.
24 25 26 |
# File 'lib/cocoapods-core/specification/set.rb', line 24 def name @name end |
#sources ⇒ Array<Source> (readonly)
Returns the sources that contain the specifications for the available versions of a Pod.
29 30 31 |
# File 'lib/cocoapods-core/specification/set.rb', line 29 def sources @sources end |
Instance Method Details
#==(other) ⇒ Object
144 145 146 |
# File 'lib/cocoapods-core/specification/set.rb', line 144 def ==(other) self.class === other && @name == other.name && @sources.map(&:name) == other.sources.map(&:name) end |
#dependency ⇒ Dependency
Returns a dependency that includes all the versions requirements of the stored dependencies.
74 75 76 77 78 |
# File 'lib/cocoapods-core/specification/set.rb', line 74 def dependency @dependencies.inject(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.
123 124 125 |
# File 'lib/cocoapods-core/specification/set.rb', line 123 def highest_version versions.first end |
#highest_version_spec_path ⇒ Pathname
Returns The path of the highest version.
129 130 131 |
# File 'lib/cocoapods-core/specification/set.rb', line 129 def highest_version_spec_path specification_path_for_version(highest_version) 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.
62 63 64 65 66 67 68 69 |
# File 'lib/cocoapods-core/specification/set.rb', line 62 def required_by(dependency, dependent_name) unless @required_by.empty? || dependency.requirement.satisfied_by?(Version.new(required_version.to_s)) raise Informative, "#{dependent_name} tries to activate `#{dependency}', but already activated version `#{required_version}' by #{@required_by.to_sentence}." end @specification = nil @required_by << dependent_name @dependencies << dependency end |
#required_version ⇒ Version
This should simply return nil. CocoaPods should raise instead.
Returns the highest version that satisfies the stored dependencies.
105 106 107 108 109 110 111 112 |
# File 'lib/cocoapods-core/specification/set.rb', line 105 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 alphabetical order of their names is used to disambiguate.
Returns the top level specification of the Pod for the #required_version.
87 88 89 |
# File 'lib/cocoapods-core/specification/set.rb', line 87 def specification @specification ||= Specification.from_file(specification_path_for_version(required_version)) end |
#specification_path_for_version(version) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/cocoapods-core/specification/set.rb', line 91 def specification_path_for_version(version) sources = [] versions_by_source.each do |source, source_versions| sources << source if source_versions.include?(required_version) end source = sources.sort_by(&:name).first source.specification_path(name, required_version) end |
#to_hash ⇒ Hash
Returns a hash representation of the set composed by dumb data types.
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/cocoapods-core/specification/set.rb', line 164 def to_hash versions = versions_by_source.inject({}) 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
148 149 150 |
# File 'lib/cocoapods-core/specification/set.rb', line 148 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.
117 118 119 |
# File 'lib/cocoapods-core/specification/set.rb', line 117 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.
136 137 138 139 140 141 142 |
# File 'lib/cocoapods-core/specification/set.rb', line 136 def versions_by_source result = {} sources.each do |source| result[source] = source.versions(name) end result end |