Class: Pod::Specification::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-core/specification/set.rb,
lib/cocoapods-core/specification/set/presenter.rb

Overview

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.

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

External

Defined Under Namespace

Classes: External, Head, Presenter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, sources = []) ⇒ Set

Returns a new instance of Set.

Parameters:

  • name (String)

    the name of the Pod.

  • sources (Array<Source>, Source) (defaults to: [])

    the sources that contain a Pod.



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

#nameString (readonly)

Returns the name of the Pod.

Returns:

  • (String)

    the name of the Pod.



19
20
21
# File 'lib/cocoapods-core/specification/set.rb', line 19

def name
  @name
end

#sourcesArray<Source> (readonly)

Returns the sources that contain the specifications for the available versions of a Pod.

Returns:

  • (Array<Source>)

    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_versionVersion

Returns The highest version known of the specification.

Returns:

  • (Version)

    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_pathPathname

Note:

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.

Returns:

  • (Pathname)

    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

#specificationSpecification

Note:

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.

Returns:

  • (Specification)

    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_nameSpecification

Returns the top level specification for this set for any version.

Returns:

  • (Specification)

    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.

Returns:

  • (Array<String>)

    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_hashHash

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

Examples:


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

Returns:

  • (Hash)

    The hash representation.



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_sObject 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

#versionsArray<Version>

Returns all the available versions for the Pod, sorted from highest to lowest.

Returns:

  • (Array<Version>)

    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_sourceHash{Source => Version}

Returns all the available versions for the Pod grouped by source.

Returns:

  • (Hash{Source => Version})

    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