Class: Pod::Source::Aggregate
- Inherits:
-
Object
- Object
- Pod::Source::Aggregate
- Defined in:
- lib/cocoapods-core/source/aggregate.rb
Overview
The Aggregate manages a directory of sources repositories.
Instance Attribute Summary collapse
-
#repos_dir ⇒ Pathname
readonly
The directory were the repositories are stored.
Search collapse
-
#search(dependency) ⇒ Set?
A set for a given dependency including all the Pod::Source that contain the Pod.
-
#search_by_name(query, full_text_search = false) ⇒ Array<Set>
The sets that contain the search term.
Search Index collapse
-
#generate_search_index ⇒ Hash{String=>Hash}
Generates from scratch the search data for all the sources of the aggregate.
-
#update_search_index(search_data) ⇒ Hash{String=>Hash}
Updates inline the given search data with the information stored in all the sources.
Instance Method Summary collapse
-
#all ⇒ Array<Source>
All the sources.
-
#all_pods ⇒ Array<String>
The names of all the pods available.
-
#all_sets ⇒ Array<Set>
The sets for all the pods available.
-
#dirs ⇒ Array<Pathname>
The directories where the sources are stored.
-
#initialize(repos_dir) ⇒ Aggregate
constructor
A new instance of Aggregate.
-
#representative_set(name) ⇒ Set
Returns a set configured with the source which contains the highest version in the aggregate.
Constructor Details
#initialize(repos_dir) ⇒ Aggregate
Returns a new instance of Aggregate.
12 13 14 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 12 def initialize(repos_dir) @repos_dir = repos_dir end |
Instance Attribute Details
#repos_dir ⇒ Pathname (readonly)
Returns the directory were the repositories are stored.
8 9 10 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 8 def repos_dir @repos_dir end |
Instance Method Details
#all ⇒ Array<Source>
Returns all the sources.
18 19 20 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 18 def all @sources ||= dirs.map { |repo| Source.new(repo) }.sort_by(&:name) end |
#all_pods ⇒ Array<String>
Returns the names of all the pods available.
24 25 26 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 24 def all_pods all.map(&:pods).flatten.uniq end |
#all_sets ⇒ Array<Set>
Implementation detail: The sources don’t cache their values because they might change in response to an update. Therefore this method to prevent slowness caches the values before processing them.
Returns the sets for all the pods available.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 35 def all_sets pods_by_source = {} all.each do |source| pods_by_source[source] = source.pods end sources = pods_by_source.keys 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 |
#dirs ⇒ Array<Pathname>
If the repos dir doesn’t exits this will return an empty array.
Returns the directories where the sources are stored.
56 57 58 59 60 61 62 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 56 def dirs if repos_dir.exist? repos_dir.children.select(&:directory?) else [] end end |
#generate_search_index ⇒ Hash{String=>Hash}
Generates from scratch the search data for all the sources of the aggregate. This operation can take a considerable amount of time (seconds) as it needs to evaluate the most representative podspec for each Pod.
153 154 155 156 157 158 159 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 153 def generate_search_index result = {} all_sets.each do |set| result[set.name] = search_data_from_set(set) end result end |
#representative_set(name) ⇒ Set
Returns a set configured with the source which contains the highest version in the aggregate.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 73 def representative_set(name) representative_source = nil highest_version = nil all.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 Specification::Set.new(name, representative_source) 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.
102 103 104 105 106 107 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 102 def search(dependency) sources = all.select { |s| s.search(dependency) } unless sources.empty? Specification::Set.new(dependency.root_name, sources) end end |
#search_by_name(query, full_text_search = false) ⇒ Array<Set>
Clients should raise not this method.
Returns the sets that contain the search term.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 117 def search_by_name(query, full_text_search = false) pods_by_source = {} result = [] all.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| sources = [] pods_by_source.each do |source, pods| sources << source if pods.include?(pod) end result << Specification::Set.new(pod, 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 |
#update_search_index(search_data) ⇒ Hash{String=>Hash}
This procedure is considerably faster as it only needs to load the most representative spec of the new or updated Pods.
Updates inline the given search data with the information stored in all the sources. The update skips the Pods for which the version of the search data is the same of the highest version known to the aggregate. This can lead to updates in podspecs being skipped until a new version is released.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/cocoapods-core/source/aggregate.rb', line 173 def update_search_index(search_data) enumerated_names = [] all_sets.each do |set| enumerated_names << set.name set_data = search_data[set.name] has_data = set_data && set_data['version'] if has_data stored_version = Version.new(set_data['version']) if stored_version < set.required_version search_data[set.name] = search_data_from_set(set) end else search_data[set.name] = search_data_from_set(set) end end stored_names = search_data.keys delted_names = stored_names - enumerated_names delted_names.each do |name| search_data.delete(name) end search_data end |