class Pod::Specification::Set

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.

@note The order in which the sets are provided is used to select a

specification if multiple are available for a given version.

@note The set class is not and should be not aware of the backing store

of a Source.

Attributes

name[R]

@return [String] the name of the Pod.

sources[R]

@return [Array<Source>] the sources that contain the specifications for

the available versions of a Pod.

Public Class Methods

new(name, sources = []) click to toggle source

@param [String] name

the name of the Pod.

@param [Array<Source>,Source] sources

the sources that contain a Pod.
# File lib/cocoapods-core/specification/set.rb, line 32
def initialize(name, sources = [])
  @name = name
  @sources = Array(sources)
end

Public Instance Methods

==(other) click to toggle source
# 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() click to toggle source

@return [Version] The highest version known of the specification.

# File lib/cocoapods-core/specification/set.rb, line 80
def highest_version
  versions.first
end
highest_version_spec_path() click to toggle source

@return [Pathname] The path of the highest version.

@note If multiple sources have a specification for the

{#required_version}, the order in which they are provided
is used to disambiguate.
# 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
inspect()
Alias for: to_s
specification() click to toggle source

@return [Specification] the top level specification of the Pod for the

{#required_version}.

@note If multiple sources have a specification for the

{#required_version}, the order in which they are provided
is used to disambiguate.
# 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() click to toggle source

@return [Specification] the top level specification for this set for any version.

# 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) click to toggle source

@return [Array<String>] the paths to specifications for the given

version
# 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() click to toggle source

Returns a hash representation of the set composed by dumb data types.

@example

"name" => "CocoaLumberjack",
"versions" => { "master" => [ "1.6", "1.3.3"] },
"highest_version" => "1.6",
"highest_version_spec" => 'REPO/CocoaLumberjack/1.6/CocoaLumberjack.podspec'

@return [Hash] The hash representation.

# 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() click to toggle source
# File lib/cocoapods-core/specification/set.rb, line 109
def to_s
  "#<#{self.class.name} for `#{name}' available at `#{sources.map(&:name).join(', ')}'>"
end
Also aliased as: inspect
versions() click to toggle source

@return [Array<Version>] all the available versions for the Pod, sorted

from highest to lowest.
# File lib/cocoapods-core/specification/set.rb, line 74
def versions
  @versions ||= versions_by_source.values.flatten.uniq.sort.reverse
end
versions_by_source() click to toggle source

@return [Hash{Source => Version}] all the available versions for the

Pod grouped by source.
# 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