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



90
91
92
93
94
# File 'lib/cocoapods-core/specification/set.rb', line 90

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.



65
66
67
# File 'lib/cocoapods-core/specification/set.rb', line 65

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.



75
76
77
# File 'lib/cocoapods-core/specification/set.rb', line 75

def 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
# File 'lib/cocoapods-core/specification/set.rb', line 44

def specification
  Specification.from_file(highest_version_spec_path)
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



51
52
53
54
# File 'lib/cocoapods-core/specification/set.rb', line 51

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.



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cocoapods-core/specification/set.rb', line 112

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



96
97
98
# File 'lib/cocoapods-core/specification/set.rb', line 96

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.



59
60
61
# File 'lib/cocoapods-core/specification/set.rb', line 59

def 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.



82
83
84
85
86
87
88
# File 'lib/cocoapods-core/specification/set.rb', line 82

def versions_by_source
  result = {}
  sources.each do |source|
    result[source] = source.versions(name)
  end
  result
end