Class: Pod::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-core/source.rb,
lib/cocoapods-core/source/acceptor.rb,
lib/cocoapods-core/source/aggregate.rb,
lib/cocoapods-core/source/health_reporter.rb

Overview

The Source class is responsible to manage a collection of podspecs.

The backing store of the podspecs collection is an implementation detail abstracted from the rest of CocoaPods.

The default implementation uses a git repo as a backing store, where the podspecs are namespaced as:

"#{SPEC_NAME}/#{VERSION}/#{SPEC_NAME}.podspec"

Defined Under Namespace

Classes: Acceptor, Aggregate, HealthReporter

Instance Attribute Summary collapse

Queering the source collapse

Searching the source collapse

Representations collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Source

Returns a new instance of Source.

Parameters:

  • repo (Pathname, String)

    @see #repo.



25
26
27
# File 'lib/cocoapods-core/source.rb', line 25

def initialize(repo)
  @repo = Pathname.new(repo)
end

Instance Attribute Details

#repoPathname (readonly)

Returns the location of the repo of the source.

Returns:

  • (Pathname)

    the location of the repo of the source.



21
22
23
# File 'lib/cocoapods-core/source.rb', line 21

def repo
  @repo
end

Instance Method Details

#<=>(other) ⇒ Integer

Note:

Source are compared by the alphabetical order of their name, and this convention should be used in any case where sources need to be disambiguated.

Returns compares a source with another one for sorting purposes.

Returns:

  • (Integer)

    compares a source with another one for sorting purposes.



45
46
47
# File 'lib/cocoapods-core/source.rb', line 45

def <=> (other)
  name <=> other.name
end

#all_specsArray<Specification>

Returns all the specifications contained by the source.

Returns:

  • (Array<Specification>)

    all the specifications contained by the source.



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/cocoapods-core/source.rb', line 116

def all_specs
  specs = pods.map do |name|
    begin
      versions(name).map { |version| specification(name, version) }
    rescue
      CoreUI.warn "Skipping `#{name}` because the podspec contains errors."
      next
    end
  end
  specs.flatten.compact
end

#nameString Also known as: to_s

Returns the name of the source.

Returns:

  • (String)

    the name of the source.



31
32
33
# File 'lib/cocoapods-core/source.rb', line 31

def name
  repo.basename.to_s
end

#pod_setsArray<Sets>

Returns the sets of all the Pods.

Returns:

  • (Array<Sets>)

    the sets of all the Pods.



63
64
65
# File 'lib/cocoapods-core/source.rb', line 63

def pod_sets
  pods.map { |pod| Specification::Set.new(pod, self) }
end

#podsArray<String>

Returns the list of the name of all the Pods.

Returns:

  • (Array<String>)

    the list of the name of all the Pods.



55
56
57
58
59
# File 'lib/cocoapods-core/source.rb', line 55

def pods
  specs_dir.children.map do |child|
    child.basename.to_s if child.directory? && child.basename.to_s != '.git'
  end.compact
end

#search(dependency) ⇒ Set

Returns a set for a given dependency. The set is identified by the name of the dependency and takes into account subspecs.

Returns:

  • (Set)

    a set for a given dependency. The set is identified by the name of the dependency and takes into account subspecs.



135
136
137
138
139
140
141
142
143
# File 'lib/cocoapods-core/source.rb', line 135

def search(dependency)
  pod_sets.find do |set|
    # First match the (top level) name, which does not yet load the spec from disk
    set.name == dependency.root_name &&
      # Now either check if it's a dependency on the top level spec, or if it's not
      # check if the requested subspec exists in the top level spec.
      set.specification.subspec_by_name(dependency.name)
  end
end

#search_by_name(query, full_text_search = false) ⇒ Array<Set>

Note:

full text search requires to load the specification for each pod, hence is considerably slower.

Returns The list of the sets that contain the search term.

Parameters:

  • query (String)

    the search term.

  • full_text_search (Bool) (defaults to: false)

    whether the search should be limited to the name of the Pod or should include also the author, the summary, and the description.

Returns:

  • (Array<Set>)

    The list of the sets that contain the search term.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/cocoapods-core/source.rb', line 157

def search_by_name(query, full_text_search = false)
  pod_sets.map do |set|
    if full_text_search
      begin
        s = set.specification
        text = "#{s.name} #{s.authors} #{s.summary} #{s.description}"
      rescue
        CoreUI.warn "Skipping `#{set.name}` because the podspec contains errors."
      end
    else
      text = set.name
    end
    set if text && text.downcase.include?(query.downcase)
  end.compact
end

#specification(name, version) ⇒ Specification

Returns the specification for a given version of Pod.

Parameters:

  • @see

    specification_path

Returns:

  • (Specification)

    the specification for a given version of Pod.



86
87
88
# File 'lib/cocoapods-core/source.rb', line 86

def specification(name, version)
  Specification.from_file(specification_path(name, version))
end

#specification_path(name, version) ⇒ Pathname

Returns the path of the specification with the given name and version.

Parameters:

  • name (String)

    the name of the Pod.

  • version (Version, String)

    the version for the specification.

Returns:

  • (Pathname)

    The path of the specification.



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cocoapods-core/source.rb', line 100

def specification_path(name, version)
  path = specs_dir + name + version.to_s
  specification_path = path + "#{name}.podspec.yaml"
  unless specification_path.exist?
    specification_path = path + "#{name}.podspec"
  end
  unless specification_path.exist?
    raise StandardError, "Unable to find the specification #{name} " \
      "(#{version}) in the #{name} source."
  end
  specification_path
end

#to_hashHash{String=>{String=>Specification}}

Returns the static representation of all the specifications grouped first by name and then by version.

Returns:

  • (Hash{String=>{String=>Specification}})

    the static representation of all the specifications grouped first by name and then by version.



181
182
183
184
185
186
187
188
# File 'lib/cocoapods-core/source.rb', line 181

def to_hash
  hash = {}
  all_specs.each do |spec|
    hash[spec.name] ||= {}
    hash[spec.name][spec.version.version] = spec.to_hash
  end
  hash
end

#to_yamlString

Returns the YAML encoded #to_hash representation.

Returns:

  • (String)

    the YAML encoded #to_hash representation.



192
193
194
195
# File 'lib/cocoapods-core/source.rb', line 192

def to_yaml
  require 'yaml'
  to_hash.to_yaml
end

#versions(name) ⇒ Array<Version>

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

Parameters:

  • name (String)

    the name of the Pod.

Returns:

  • (Array<Version>)

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



73
74
75
76
77
78
79
80
# File 'lib/cocoapods-core/source.rb', line 73

def versions(name)
  pod_dir = specs_dir + name
  return unless pod_dir.exist?
  pod_dir.children.map do |v|
    basename = v.basename.to_s
    Version.new(basename) if v.directory? && basename[0,1] != '.'
  end.compact.sort.reverse
end