class Pod::Source::Manager

Public Instance Methods

add_source(source) click to toggle source

Adds the provided source to the list of sources

@param [Source] source the source to add

# File lib/cocoapods/sources_manager.rb, line 158
def add_source(source)
  all << source unless all.any? { |s| s.url == source || s.name == source.name }
end
cdn_url?(url) click to toggle source

Determines whether ‘url` is a CocoaPods CDN URL.

@return [Boolean] whether ‘url` is a CocoaPods CDN URL,

@param [String] url

The URL of the source.
# File lib/cocoapods/sources_manager.rb, line 73
def cdn_url?(url)
  return false unless url =~ %r{^https?:\/\/}

  uri_options = {}

  netrc_info = Netrc.read
  uri = URI.parse(url)
  return false unless uri.userinfo.nil?

  netrc_host = uri.host
  credentials = netrc_info[netrc_host]
  uri_options[:http_basic_authentication] = credentials if credentials

  response = OpenURI.open_uri(url.chomp('/') + '/CocoaPods-version.yml', uri_options)
  response_hash = YAML.load(response.read) # rubocop:disable Security/YAMLLoad
  response_hash.is_a?(Hash) && !Source::Metadata.new(response_hash).latest_cocoapods_version.nil?
rescue Psych::SyntaxError, ::OpenURI::HTTPError, SocketError
  return false
rescue => e
  raise Informative, "Couldn't determine repo type for URL: `#{url}`: #{e}"
end
create_source_with_url(url) click to toggle source

Adds the source whose {Source#url} is equal to ‘url`, in a manner similarly to `pod repo add` if it is not found.

@raise If no source with the given ‘url` could be created,

@return [Source] The source whose {Source#url} is equal to ‘url`,

@param [String] url

The URL of the source.
# File lib/cocoapods/sources_manager.rb, line 35
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
    message = "Unable to add a source with url `#{url}` " \
      "named `#{name}`.\n"
    message << "(#{e})\n" if Config.instance.verbose?
    message << 'You can try adding it manually in ' \
      "`#{Config.instance.repos_dir}` or via `pod repo add`."
    raise Informative, message
  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) click to toggle 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.

@raise If no source with the given ‘url` could be created,

@return [Source] The source whose {Source#url} is equal to ‘url`,

@param [String] url

The URL of the source.
# File lib/cocoapods/sources_manager.rb, line 21
def find_or_create_source_with_url(url)
  source_with_url(url) || create_source_with_url(url)
end
search_index_path() click to toggle source

@return [Pathname] The path where the search index should be stored.

# File lib/cocoapods/sources_manager.rb, line 111
def search_index_path
  @search_index_path ||= Config.instance.search_index_file
end
source_with_name_or_url(name_or_url) click to toggle source

Returns the source whose {Source#name} or {Source#url} is equal to the given ‘name_or_url`.

@return [Source] The source whose {Source#name} or {Source#url} is equal to the

given `name_or_url`.

@param [String] name_or_url

The name or the URL of the source.
# File lib/cocoapods/sources_manager.rb, line 104
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) click to toggle source

Updates the local clone of the spec-repo with the given name or of all the git repos if the name is omitted.

@param [String] source_name

@param [Boolean] show_output

@return [void]

# File lib/cocoapods/sources_manager.rb, line 126
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