class Pod::Config

Stores the global configuration of CocoaPods.

Constants

DEFAULTS

The default settings for the configuration.

Users can specify custom settings in `~/.cocoapods/config.yaml`. An example of the contents of this file might look like:

---
skip_repo_update: true
new_version_message: false
PODFILE_NAMES

@return [Array<String>] The filenames that the Podfile can have ordered

by priority.

Attributes

instance[W]
allow_root[RW]

@return [Bool] Whether CocoaPods is allowed to run as root.

allow_root?[RW]

@return [Bool] Whether CocoaPods is allowed to run as root.

cache_root[RW]

@return [Pathname] The directory where CocoaPods should cache remote data

and other expensive to compute information.
installation_root[W]
new_version_message[RW]

@return [Bool] Whether a message should be printed when a new version of

CocoaPods is available.
new_version_message?[RW]

@return [Bool] Whether a message should be printed when a new version of

CocoaPods is available.
podfile[W]
repos_dir[W]
sandbox_root[W]
silent[RW]

@return [Bool] Whether CocoaPods should produce not output.

silent?[RW]

@return [Bool] Whether CocoaPods should produce not output.

skip_download_cache[RW]

@return [Bool] Whether the installer should skip the download cache.

skip_download_cache?[RW]

@return [Bool] Whether the installer should skip the download cache.

verbose[RW]

@return [Bool] Whether CocoaPods should provide detailed output about the

performed actions.
verbose?[RW]

@return [Bool] Whether CocoaPods should provide detailed output about the

performed actions.

Public Class Methods

instance() click to toggle source

@return [Config] the current config instance creating one if needed.

# File lib/cocoapods/config.rb, line 342
def self.instance
  @instance ||= new
end
new(use_user_settings = true) click to toggle source

@!group Initialization

# File lib/cocoapods/config.rb, line 105
def initialize(use_user_settings = true)
  configure_with(DEFAULTS)

  unless ENV['CP_HOME_DIR'].nil?
    @cache_root = home_dir + 'cache'
  end

  if use_user_settings && user_settings_file.exist?
    require 'yaml'
    user_settings = YAML.load_file(user_settings_file)
    configure_with(user_settings)
  end

  unless ENV['CP_CACHE_DIR'].nil?
    @cache_root = Pathname.new(ENV['CP_CACHE_DIR']).expand_path
  end
end

Public Instance Methods

default_podfile_path() click to toggle source

Returns the path of the default Podfile pods.

@note The file is expected to be named Podfile.default

@return [Pathname]

# File lib/cocoapods/config.rb, line 243
def default_podfile_path
  @default_podfile_path ||= templates_dir + 'Podfile.default'
end
default_test_podfile_path() click to toggle source

Returns the path of the default Podfile test pods.

@note The file is expected to be named Podfile.test

@return [Pathname]

# File lib/cocoapods/config.rb, line 253
def default_test_podfile_path
  @default_test_podfile_path ||= templates_dir + 'Podfile.test'
end
exclude_from_backup(dir) click to toggle source

Excludes the given dir from Time Machine backups.

@param [Pathname] dir

The directory to exclude from Time Machine backups.

@return [void]

# File lib/cocoapods/config.rb, line 329
def exclude_from_backup(dir)
  return if Gem.win_platform?
  system('tmutil', 'addexclusion', dir.to_s, %i(out err) => File::NULL)
end
home_dir() click to toggle source

@return [Pathname] the directory where repos, templates and configuration

files are stored.
# File lib/cocoapods/config.rb, line 136
def home_dir
  @home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.cocoapods').expand_path
end
installation_root() click to toggle source

@return [Pathname] the root of the CocoaPods installation where the

Podfile is located.
# File lib/cocoapods/config.rb, line 164
def installation_root
  @installation_root ||= begin
    current_dir = Pathname.new(Dir.pwd.unicode_normalize(:nfkc))
    current_path = current_dir
    until current_path.root?
      if podfile_path_in_dir(current_path)
        installation_root = current_path
        unless current_path == current_dir
          UI.puts("[in #{current_path}]")
        end
        break
      else
        current_path = current_path.parent
      end
    end
    installation_root || current_dir
  end
end
Also aliased as: project_root
lockfile() click to toggle source

@return [Lockfile] The Lockfile to use for the current execution. @return [Nil] If no Lockfile is available.

# File lib/cocoapods/config.rb, line 212
def lockfile
  @lockfile ||= Lockfile.from_file(lockfile_path) if lockfile_path
end
lockfile_path() click to toggle source

Returns the path of the Lockfile.

@note The Lockfile is named `Podfile.lock`.

# File lib/cocoapods/config.rb, line 233
def lockfile_path
  @lockfile_path ||= installation_root + 'Podfile.lock'
end
podfile() click to toggle source

@return [Podfile] The Podfile to use for the current execution. @return [Nil] If no Podfile is available.

# File lib/cocoapods/config.rb, line 204
def podfile
  @podfile ||= Podfile.from_file(podfile_path) if podfile_path
end
podfile_path() click to toggle source

Returns the path of the Podfile.

@note The Podfile can be named either `CocoaPods.podfile.yaml`,

`CocoaPods.podfile` or `Podfile`.  The first two are preferred as
they allow to specify an OS X UTI.

@return [Pathname] @return [Nil]

# File lib/cocoapods/config.rb, line 225
def podfile_path
  @podfile_path ||= podfile_path_in_dir(installation_root)
end
podfile_path_in_dir(dir) click to toggle source

Returns the path of the Podfile in the given dir if any exists.

@param [Pathname] dir

The directory where to look for the Podfile.

@return [Pathname] The path of the Podfile. @return [Nil] If not Podfile was found in the given dir

# File lib/cocoapods/config.rb, line 312
def podfile_path_in_dir(dir)
  PODFILE_NAMES.each do |filename|
    candidate = dir + filename
    if candidate.file?
      return candidate
    end
  end
  nil
end
project_pods_root()
Alias for: sandbox_root
project_root()
Alias for: installation_root
repos_dir() click to toggle source

@return [Pathname] the directory where the CocoaPods sources are stored.

# File lib/cocoapods/config.rb, line 142
def repos_dir
  @repos_dir ||= Pathname.new(ENV['CP_REPOS_DIR'] || (home_dir + 'repos')).expand_path
end
sandbox() click to toggle source

@return [Sandbox] The sandbox of the current project.

# File lib/cocoapods/config.rb, line 197
def sandbox
  @sandbox ||= Sandbox.new(sandbox_root)
end
sandbox_root() click to toggle source

@return [Pathname] The root of the sandbox.

# File lib/cocoapods/config.rb, line 188
def sandbox_root
  @sandbox_root ||= installation_root + 'Pods'
end
Also aliased as: project_pods_root
search_index_file() click to toggle source

@return [Pathname] The file to use to cache the search data.

# File lib/cocoapods/config.rb, line 259
def search_index_file
  cache_root + 'search_index.json'
end
sources_manager() click to toggle source

@return [Source::Manager] the source manager for the spec repos in `repos_dir`

# File lib/cocoapods/config.rb, line 150
def sources_manager
  return @sources_manager if @sources_manager && @sources_manager.repos_dir == repos_dir
  @sources_manager = Source::Manager.new(repos_dir)
end
templates_dir() click to toggle source

@return [Pathname] the directory where the CocoaPods templates are stored.

# File lib/cocoapods/config.rb, line 157
def templates_dir
  @templates_dir ||= Pathname.new(ENV['CP_TEMPLATES_DIR'] || (home_dir + 'templates')).expand_path
end
with_changes(changes) { || ... } click to toggle source

Applies the given changes to the config for the duration of the given block.

@param [Hash<#to_sym,Object>] changes

the changes to merge temporarily with the current config

@yield [] is called while the changes are applied

# File lib/cocoapods/config.rb, line 34
def with_changes(changes)
  old = {}
  changes.keys.each do |key|
    key = key.to_sym
    old[key] = send(key) if respond_to?(key)
  end
  configure_with(changes)
  yield if block_given?
ensure
  configure_with(old)
end

Private Instance Methods

configure_with(values_by_key) click to toggle source

Sets the values of the attributes with the given hash.

@param [Hash{String,Symbol => Object}] values_by_key

The values of the attributes grouped by key.

@return [void]

# File lib/cocoapods/config.rb, line 282
def configure_with(values_by_key)
  return unless values_by_key
  values_by_key.each do |key, value|
    if key.to_sym == :cache_root
      value = Pathname.new(value).expand_path
    end
    instance_variable_set("@#{key}", value)
  end
end
user_settings_file() click to toggle source

@return [Pathname] The path of the file which contains the user settings.

# File lib/cocoapods/config.rb, line 271
def user_settings_file
  home_dir + 'config.yaml'
end