Class: Pod::SourcesManager
- Inherits:
-
Object
- Object
- Pod::SourcesManager
- Extended by:
- Config::Mixin, Executable
- Defined in:
- lib/cocoapods/sources_manager.rb
Overview
Manages all the sources known to the running CocoaPods Instance.
Class Attribute Summary collapse
-
.updated_search_index ⇒ Hash{String => String}
Creates or updates the search data and returns it.
Master repo collapse
-
.master_repo_dir ⇒ Pathname
The path of the master repo.
-
.master_repo_functional? ⇒ Bool
Checks if the master repo is usable.
Class Method Summary collapse
-
.aggregate ⇒ Source::Aggregate
The aggregate of all the sources known to this installation of CocoaPods.
-
.all ⇒ Array<Source>
The list of all the sources known to this installation of CocoaPods.
-
.all_sets ⇒ Array<Specification::Set>
The list of all the specification sets know to this installation of CocoaPods.
-
.check_version_information(dir) ⇒ void
Checks the version information of the source with the given directory.
-
.cocoapods_update?(version_information) ⇒ Bool
Checks whether there is a CocoaPods given the version information of a repo.
-
.git_repo?(dir) ⇒ Bool
Returns whether a source is a GIT repo.
-
.repo_compatible?(dir) ⇒ Bool
Returns whether a source is compatible with the current version of CocoaPods.
-
.search(dependency) ⇒ Set?
Search all the sources to match the set for the given dependency.
-
.search_by_name(query, full_text_search = false) ⇒ Array<Set>
Search all the sources with the given search term.
-
.search_index_path ⇒ Pathname
The path where the search index should be stored.
-
.update(source_name = nil, show_output = false) ⇒ void
Updates the local clone of the spec-repo with the given name or of all the git repos if the name is omitted.
-
.version_information(dir) ⇒ Hash
Returns the contents of the ‘CocoaPods-version.yml` file, which stores information about CocoaPods versions.
Methods included from Config::Mixin
Methods included from Executable
Class Attribute Details
.updated_search_index ⇒ Hash{String => String}
This operation is fairly expensive, because of the YAML conversion.
Creates or updates the search data and returns it. The search data groups by name the following information for each set:
- version
- summary
- description
-
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cocoapods/sources_manager.rb', line 97 def updated_search_index unless @updated_search_index if search_index_path.exist? stored_index = YAML.load(search_index_path.read) if stored_index && stored_index.is_a?(Hash) search_index = aggregate.update_search_index(stored_index) else search_index = aggregate.generate_search_index end else search_index = aggregate.generate_search_index end File.open(search_index_path, 'w') {|f| f.write(search_index.to_yaml) } @updated_search_index = search_index end @updated_search_index end |
Class Method Details
.aggregate ⇒ Source::Aggregate
Returns the aggregate of all the sources known to this installation of CocoaPods.
14 15 16 |
# File 'lib/cocoapods/sources_manager.rb', line 14 def aggregate Source::Aggregate.new(config.repos_dir) end |
.all ⇒ Array<Source>
Returns the list of all the sources known to this installation of CocoaPods.
21 22 23 |
# File 'lib/cocoapods/sources_manager.rb', line 21 def all aggregate.all end |
.all_sets ⇒ Array<Specification::Set>
Returns the list of all the specification sets know to this installation of CocoaPods.
28 29 30 |
# File 'lib/cocoapods/sources_manager.rb', line 28 def all_sets aggregate.all_sets end |
.check_version_information(dir) ⇒ void
This method returns an undefined value.
Checks the version information of the source with the given directory. It raises if the source is not compatible and if there is CocoaPods update it informs the user.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/cocoapods/sources_manager.rb', line 185 def check_version_information(dir) versions = version_information(dir) unless repo_compatible?(dir) min, max = versions['min'], versions['max'] version_msg = ( min == max ) ? min : "#{min} - #{max}" raise Informative, "The `#{dir.basename}` repo requires " \ "CocoaPods #{version_msg}\n".red + "Update CocoaPods, or checkout the appropriate tag in the repo." end if config. && cocoapods_update?(versions) UI.puts "\nCocoaPods #{versions['last']} is available.\n".green end end |
.cocoapods_update?(version_information) ⇒ Bool
Checks whether there is a CocoaPods given the version information of a repo.
226 227 228 229 |
# File 'lib/cocoapods/sources_manager.rb', line 226 def cocoapods_update?(version_information) version = version_information['last'] version && Gem::Version.new(version) > Gem::Version.new(Pod::VERSION) end |
.git_repo?(dir) ⇒ Bool
Returns whether a source is a GIT repo.
169 170 171 172 |
# File 'lib/cocoapods/sources_manager.rb', line 169 def git_repo?(dir) Dir.chdir(dir) { `git rev-parse >/dev/null 2>&1` } $?.exitstatus.zero? end |
.master_repo_dir ⇒ Pathname
Returns The path of the master repo.
258 259 260 |
# File 'lib/cocoapods/sources_manager.rb', line 258 def master_repo_dir config.repos_dir + 'master' end |
.master_repo_functional? ⇒ Bool
Note this is used to automatically setup the master repo if needed.
Returns Checks if the master repo is usable.
267 268 269 |
# File 'lib/cocoapods/sources_manager.rb', line 267 def master_repo_functional? master_repo_dir.exist? && repo_compatible?(master_repo_dir) end |
.repo_compatible?(dir) ⇒ Bool
Returns whether a source is compatible with the current version of CocoaPods.
208 209 210 211 212 213 214 215 216 |
# File 'lib/cocoapods/sources_manager.rb', line 208 def repo_compatible?(dir) versions = version_information(dir) min, max = versions['min'], versions['max'] bin_version = Gem::Version.new(Pod::VERSION) supports_min = !min || bin_version >= Gem::Version.new(min) supports_max = !max || bin_version <= Gem::Version.new(max) supports_min && supports_max end |
.search(dependency) ⇒ Set?
Search all the sources to match the set for the given dependency.
40 41 42 |
# File 'lib/cocoapods/sources_manager.rb', line 40 def search(dependency) aggregate.search(dependency) end |
.search_by_name(query, full_text_search = false) ⇒ Array<Set>
Full text search requires to load the specification for each pod, hence is considerably slower.
Search all the sources with the given search term.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cocoapods/sources_manager.rb', line 61 def search_by_name(query, full_text_search = false) if full_text_search set_names = [] updated_search_index.each do |name, set_data| text = name.dup if full_text_search text << set_data['authors'].to_s if set_data['authors'] text << set_data['summary'] if set_data['summary'] text << set_data['description'] if set_data['description'] end set_names << name if text.downcase.include?(query.downcase) end sets = set_names.sort.map { |name| aggregate.represenative_set(name) } else sets = aggregate.search_by_name(query, false) end if sets.empty? extra = ", author, summary, or description" if full_text_search raise Informative, "Unable to find a pod with name#{extra} matching `#{query}`" end sets end |
.search_index_path ⇒ Pathname
Returns The path where the search index should be stored.
122 123 124 |
# File 'lib/cocoapods/sources_manager.rb', line 122 def search_index_path CACHE_ROOT + 'search_index.yaml' end |
.update(source_name = nil, show_output = false) ⇒ void
This method returns an undefined value.
Updates the local clone of the spec-repo with the given name or of all the git repos if the name is omitted.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/cocoapods/sources_manager.rb', line 141 def update(source_name = nil, show_output = false) if source_name specified_source = aggregate.all.find { |s| s.name == source_name } raise Informative, "Unable to find the `#{source_name}` repo." unless specified_source raise Informative, "The `#{source_name}` repo is not a git repo." unless git_repo?(specified_source.repo) sources = [specified_source] else sources = aggregate.all.select { |source| git_repo?(source.repo) } end sources.each do |source| UI.section "Updating spec repo `#{source.name}`" do Dir.chdir(source.repo) do output = git!("pull") UI.puts output if show_output && !config.verbose? end check_version_information(source.repo) end end end |
.version_information(dir) ⇒ Hash
Returns the contents of the ‘CocoaPods-version.yml` file, which stores information about CocoaPods versions.
This file is a hash with the following keys:
-
last: the last version of CocoaPods known to the source.
-
min: the minimum version of CocoaPods supported by the source.
-
max: the maximum version of CocoaPods supported by the source.
245 246 247 248 249 |
# File 'lib/cocoapods/sources_manager.rb', line 245 def version_information(dir) require 'yaml' yaml_file = dir + 'CocoaPods-version.yml' yaml_file.exist? ? YAML.load_file(yaml_file) : {} end |