Class: Pod::Source::Manager
- Inherits:
-
Object
- Object
- Pod::Source::Manager
- Defined in:
- lib/cocoapods/sources_manager.rb
Updating Sources collapse
-
#add_source(source) ⇒ Object
Adds the provided source to the list of sources.
-
#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.
Instance Method Summary collapse
-
#cdn_url?(url) ⇒ Boolean
Determines whether
url
is a CocoaPods CDN URL. -
#create_source_with_url(url) ⇒ Source
Adds the source whose Source#url is equal to
url
, in a manner similarly topod repo add
if it is not found. -
#find_or_create_source_with_url(url) ⇒ Source
Returns the source whose Source#url is equal to
url
, adding the repo in a manner similarly topod repo add
if it is not found. -
#search_index_path ⇒ Pathname
The path where the search index should be stored.
-
#source_with_name_or_url(name_or_url) ⇒ Source
Returns the source whose Source#name or Source#url is equal to the given
name_or_url
.
Instance Method Details
#add_source(source) ⇒ Object
Adds the provided source to the list of sources
149 150 151 |
# File 'lib/cocoapods/sources_manager.rb', line 149 def add_source(source) all << source unless all.any? { |s| s.url == source || s.name == source.name } end |
#cdn_url?(url) ⇒ Boolean
Determines whether url
is a CocoaPods CDN URL.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cocoapods/sources_manager.rb', line 72 def cdn_url?(url) if url =~ %r{^https?:\/\/} require 'typhoeus' response = Typhoeus.get(url + '/CocoaPods-version.yml', :netrc_file => Netrc.default_path, :netrc => :optional) response.code == 200 && begin response_hash = YAML.load(response.body) # rubocop:disable Security/YAMLLoad response_hash.is_a?(Hash) && !Source::Metadata.new(response_hash).latest_cocoapods_version.nil? end end rescue => e raise Informative, "Couldn't determine repo type for URL: `#{url}`: #{e}" end |
#create_source_with_url(url) ⇒ Source
Adds the source whose Source#url is equal to url
,
in a manner similarly to pod repo add
if it is not found.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cocoapods/sources_manager.rb', line 34 def create_source_with_url(url) name = name_for_url(url) is_cdn = cdn_url?(url) # Hack to ensure that `repo add` output is shown. previous_title_level = UI.title_level UI.title_level = 0 begin if is_cdn Command::Repo::AddCDN.parse([name, url]).run else Command::Repo::Add.parse([name, url]).run end rescue Informative => e = "Unable to add a source with url `#{url}` " \ "named `#{name}`.\n" << "(#{e})\n" if Config.instance.verbose? << 'You can try adding it manually in ' \ "`#{Config.instance.repos_dir}` or via `pod repo add`." raise Informative, ensure UI.title_level = previous_title_level end source = source_with_url(url) raise "Unable to create a source with URL #{url}" unless source source end |
#find_or_create_source_with_url(url) ⇒ Source
Returns the source whose Source#url is equal to url
, adding the repo
in a manner similarly to pod repo add
if it is not found.
20 21 22 |
# File 'lib/cocoapods/sources_manager.rb', line 20 def find_or_create_source_with_url(url) source_with_url(url) || create_source_with_url(url) end |
#search_index_path ⇒ Pathname
Returns The path where the search index should be stored.
102 103 104 |
# File 'lib/cocoapods/sources_manager.rb', line 102 def search_index_path @search_index_path ||= Config.instance.search_index_file end |
#source_with_name_or_url(name_or_url) ⇒ Source
Returns the source whose Source#name or Source#url is equal to the
given name_or_url
.
95 96 97 98 |
# File 'lib/cocoapods/sources_manager.rb', line 95 def source_with_name_or_url(name_or_url) all.find { |s| s.name == name_or_url } || find_or_create_source_with_url(name_or_url) 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.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cocoapods/sources_manager.rb', line 117 def update(source_name = nil, show_output = false) if source_name sources = [updateable_source_named(source_name)] else sources = updateable_sources end changed_spec_paths = {} # Do not perform an update if the repos dir has not been setup yet. return unless repos_dir.exist? # Create the Spec_Lock file if needed and lock it so that concurrent # repo updates do not cause each other to fail File.open("#{repos_dir}/Spec_Lock", File::CREAT) do |f| f.flock(File::LOCK_EX) sources.each do |source| UI.section "Updating spec repo `#{source.name}`" do changed_source_paths = source.update(show_output) changed_spec_paths[source] = changed_source_paths if changed_source_paths.count > 0 source.verify_compatibility! end end end # Perform search index update operation in background. update_search_index_if_needed_in_background(changed_spec_paths) end |