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,
lib/cocoapods-core/source/abstract_data_provider.rb,
lib/cocoapods-core/source/file_system_data_provider.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: AbstractDataProvider, Acceptor, Aggregate, FileSystemDataProvider, HealthReporter

Instance Attribute Summary collapse

Queering the source collapse

Searching the source collapse

Representations collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo = nil) ⇒ Source

Returns a new instance of Source.

Parameters:

  • repo (Pathname, String) (defaults to: nil)

    @see #repo.



25
26
27
28
29
30
31
32
# File 'lib/cocoapods-core/source.rb', line 25

def initialize(repo = nil)
  # TODO: Temporary solution to aide the transition
  if repo.is_a?(String) || repo.is_a?(Pathname)
    @data_provider = FileSystemDataProvider.new(repo)
  else
    @data_provider = repo
  end
end

Instance Attribute Details

#data_providerAbstractDataProvider

Returns the data provider for this source.

Returns:



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

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



61
62
63
# File 'lib/cocoapods-core/source.rb', line 61

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.



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

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

#fuzzy_search(query) ⇒ Set, Nil

Returns the set of the Pod whose name fuzzily matches the given query.

Parameters:

  • query (String)

    The query to search for.

Returns:

  • (Set)

    The name of the Pod.

  • (Nil)

    If no Pod with a suitable name was found.



248
249
250
251
252
253
254
# File 'lib/cocoapods-core/source.rb', line 248

def fuzzy_search(query)
  require 'fuzzy_match'
  pod_name = FuzzyMatch.new(pods).find(query)
  if pod_name
    search(pod_name)
  end
end

#inspectString

Returns A description suitable for debugging.

Returns:

  • (String)

    A description suitable for debugging.



67
68
69
# File 'lib/cocoapods-core/source.rb', line 67

def inspect
  "#<#{self.class} name:#{name} type:#{type}>"
end

#nameString Also known as: to_s

Returns The name of the source.

Returns:

  • (String)

    The name of the source.



36
37
38
# File 'lib/cocoapods-core/source.rb', line 36

def name
  data_provider.name
end

#pod_setsArray<Sets>

Returns the sets of all the Pods.

Returns:

  • (Array<Sets>)

    the sets of all the Pods.



158
159
160
# File 'lib/cocoapods-core/source.rb', line 158

def pod_sets
  pods.map { |pod_name| set(pod_name) }
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.



79
80
81
82
83
84
85
86
# File 'lib/cocoapods-core/source.rb', line 79

def pods
  pods = data_provider.pods
  unless pods
    raise Informative, "Unable to find the #{data_provider.type} source " \
      "named: `#{data_provider.name}`"
  end
  pods
end

#search(query) ⇒ Set

TODO:

Rename to #load_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.



188
189
190
191
192
193
194
195
196
197
# File 'lib/cocoapods-core/source.rb', line 188

def search(query)
  if query.is_a?(Dependency)
    name = query.root_name
  else
    name = query
  end
  pod_sets.find do |set|
    set.name == name
  end
end

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

TODO:

Rename to #search

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. Can be a regular expression.

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



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/cocoapods-core/source.rb', line 213

def search_by_name(query, full_text_search = false)
  regexp_query = /#{query}/i
  if full_text_search
    if data_provider.is_a?(FileSystemDataProvider)
      pod_sets.reject do |set|
        texts = []
        begin
          s = set.specification
          texts << s.name
          texts += s.authors.keys
          texts << s.summary
          texts << s.description
        rescue
          CoreUI.warn "Skipping `#{set.name}` because the podspec " \
            'contains errors.'
        end
        texts.grep(regexp_query).empty?
      end
    else
      []
    end
  else
    names = pods.grep(regexp_query)
    names.map { |pod_name| set(pod_name) }
  end
end

#set(pod_name) ⇒ Sets

Returns the set for the Pod with the given name.

Parameters:

  • pod_name (String)

    The name of the Pod.

Returns:

  • (Sets)

    the set.



152
153
154
# File 'lib/cocoapods-core/source.rb', line 152

def set(pod_name)
  Specification::Set.new(pod_name, self)
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.



103
104
105
# File 'lib/cocoapods-core/source.rb', line 103

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

#specification_path(name, version) ⇒ Pathname

TODO:

Remove.

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.



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

def specification_path(name, version)
  path = specs_dir + name + version.to_s
  specification_path = path + "#{name}.podspec.json"
  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
  spec
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.



265
266
267
268
269
270
271
272
# File 'lib/cocoapods-core/source.rb', line 265

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.



276
277
278
279
# File 'lib/cocoapods-core/source.rb', line 276

def to_yaml
  require 'yaml'
  to_hash.to_yaml
end

#typeString

Returns The type of the source.

Returns:

  • (String)

    The type of the source.



48
49
50
# File 'lib/cocoapods-core/source.rb', line 48

def type
  data_provider.type
end

#urlString

Returns The URL of the source.

Returns:

  • (String)

    The URL of the source.



42
43
44
# File 'lib/cocoapods-core/source.rb', line 42

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



94
95
96
97
# File 'lib/cocoapods-core/source.rb', line 94

def versions(name)
  versions = data_provider.versions(name)
  versions.map { |version| Version.new(version) } if versions
end