Class: Pod::Source::Aggregate

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

Overview

The Aggregate manages a directory of sources repositories.

Instance Attribute Summary collapse

Search collapse

Search Index collapse

Instance Method Summary collapse

Constructor Details

#initialize(sources) ⇒ Aggregate

Returns a new instance of Aggregate.

Parameters:

  • repos_dirs (Array<Source>)

    @see Sources



12
13
14
15
# File 'lib/cocoapods-core/source/aggregate.rb', line 12

def initialize(sources)
  raise "Cannot initialize an aggregate with a nil source: (#{sources})" if sources.include?(nil)
  @sources = sources
end

Instance Attribute Details

#sourcesArray<Source> (readonly)

Returns The ordered list of sources.

Returns:

  • (Array<Source>)

    The ordered list of sources.



8
9
10
# File 'lib/cocoapods-core/source/aggregate.rb', line 8

def sources
  @sources
end

Instance Method Details

#all_podsArray<String>

Returns the names of all the pods available.

Returns:

  • (Array<String>)

    the names of all the pods available.



19
20
21
# File 'lib/cocoapods-core/source/aggregate.rb', line 19

def all_pods
  sources.map(&:pods).flatten.uniq
end

#all_setsArray<Set>

Note:

Implementation detail: The sources don’t cache their values because they might change in response to an update. Therefore this method to preserve performance caches the values before processing them.

Returns The sets for all the pods available.

Returns:

  • (Array<Set>)

    The sets for all the pods available.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cocoapods-core/source/aggregate.rb', line 30

def all_sets
  pods_by_source = {}
  sources.each do |source|
    pods_by_source[source] = source.pods
  end
  pods = pods_by_source.values.flatten.uniq

  pods.map do |pod|
    pod_sources = sources.select { |s| pods_by_source[s].include?(pod) }
    pod_sources = pod_sources.compact
    Specification::Set.new(pod, pod_sources)
  end
end

#generate_search_index_for_changes_in_source(source, spec_paths) ⇒ Hash{String=>Hash}

Generates from scratch the search data for changed specifications in given source.

Parameters:

  • source (Source)

    The source from which a search index will be generated.

  • spec_paths (Array<String>)

    Array of file path names for corresponding changed specifications.

Returns:

  • (Hash{String=>Hash})

    The search data for changed specifications.



150
151
152
153
154
155
156
# File 'lib/cocoapods-core/source/aggregate.rb', line 150

def generate_search_index_for_changes_in_source(source, spec_paths)
  pods = source.pods_for_specification_paths(spec_paths)
  sets = pods.map do |pod|
    Specification::Set.new(pod, source)
  end
  generate_search_index_for_sets(sets)
end

#generate_search_index_for_source(source) ⇒ Hash{String=>Hash}

Generates from scratch the search data for given source. This operation can take a considerable amount of time (seconds) as it needs to evaluate the most representative podspec for each Pod.

Parameters:

  • source (Source)

    The source from which a search index will be generated.

Returns:

  • (Hash{String=>Hash})

    The search data for the source.



137
138
139
# File 'lib/cocoapods-core/source/aggregate.rb', line 137

def generate_search_index_for_source(source)
  generate_search_index_for_sets(source.pod_sets)
end

#representative_set(name) ⇒ Set

Returns a set configured with the source which contains the highest version in the aggregate.

Parameters:

  • name (String)

    The name of the Pod.

Returns:

  • (Set)

    The most representative set for the Pod with the given name. Returns nil if no representative source found containing a pod with given name.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cocoapods-core/source/aggregate.rb', line 53

def representative_set(name)
  representative_source = nil
  highest_version = nil
  sources.each do |source|
    source_versions = source.versions(name)
    if source_versions
      source_version = source_versions.first
      if highest_version.nil? || (highest_version < source_version)
        highest_version = source_version
        representative_source = source
      end
    end
  end
  representative_source ? Specification::Set.new(name, representative_source) : nil
end

#search(dependency) ⇒ Set?

Returns a set for a given dependency including all the Pod::Source that contain the Pod. If no sources containing the Pod where found it returns nil.

Returns:

  • (Set, nil)

    a set for a given dependency including all the Pod::Source that contain the Pod. If no sources containing the Pod where found it returns nil.

Raises:

  • If no source including the set can be found.

See Also:



82
83
84
85
86
87
# File 'lib/cocoapods-core/source/aggregate.rb', line 82

def search(dependency)
  found_sources = sources.select { |s| s.search(dependency) }
  unless found_sources.empty?
    Specification::Set.new(dependency.root_name, found_sources)
  end
end

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

TODO:

Clients should raise not this method.

Returns the sets that contain the search term.

Returns:

  • (Array<Set>)

    the sets that contain the search term.

Raises:

  • If no source including the set can be found.

See Also:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cocoapods-core/source/aggregate.rb', line 97

def search_by_name(query, full_text_search = false)
  pods_by_source = {}
  result = []
  sources.each do |s|
    source_pods = s.search_by_name(query, full_text_search)
    pods_by_source[s] = source_pods.map(&:name)
  end

  root_spec_names = pods_by_source.values.flatten.uniq
  root_spec_names.each do |pod|
    result_sources = sources.select do |source|
      pods_by_source[source].include?(pod)
    end

    result << Specification::Set.new(pod, result_sources)
  end

  if result.empty?
    extra = ', author, summary, or description' if full_text_search
    raise Informative, 'Unable to find a pod with name' \
      "#{extra} matching `#{query}'"
  end
  result
end