Class: Pod::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/config.rb

Overview

Stores the global configuration of CocoaPods.

Defined Under Namespace

Modules: Mixin

Constant Summary collapse

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
{
  :verbose             => false,
  :silent              => false,
  :skip_download_cache => !ENV['COCOAPODS_SKIP_CACHE'].nil?,

  :new_version_message => ENV['COCOAPODS_SKIP_UPDATE_MESSAGE'].nil?,

  :cache_root          => Pathname.new(Dir.home) + 'Library/Caches/CocoaPods',
}

UI collapse

Installation collapse

Cache collapse

Initialization collapse

Paths collapse

Singleton collapse

UI collapse

Initialization collapse

Paths collapse

Private helpers collapse

Instance Method Summary collapse

Constructor Details

#initialize(use_user_settings = true) ⇒ Config


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/cocoapods/config.rb', line 100

def initialize( = true)
  configure_with(DEFAULTS)

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

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

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

Class Attribute Details

.instanceConfig


325
326
327
# File 'lib/cocoapods/config.rb', line 325

def self.instance
  @instance ||= new
end

Instance Attribute Details

#cache_rootPathname


87
88
89
# File 'lib/cocoapods/config.rb', line 87

def cache_root
  @cache_root
end

#installation_rootPathname Also known as: project_root


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/cocoapods/config.rb', line 159

def installation_root
  @installation_root ||= begin
    current_dir = Pathname.new(ActiveSupport::Multibyte::Unicode.normalize(Dir.pwd))
    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

#new_version_messageBool Also known as: new_version_message?


66
67
68
# File 'lib/cocoapods/config.rb', line 66

def new_version_message
  @new_version_message
end

#podfilePodfile, Nil


199
200
201
# File 'lib/cocoapods/config.rb', line 199

def podfile
  @podfile ||= Podfile.from_file(podfile_path) if podfile_path
end

#repos_dirPathname


137
138
139
# File 'lib/cocoapods/config.rb', line 137

def repos_dir
  @repos_dir ||= Pathname.new(ENV['CP_REPOS_DIR'] || (home_dir + 'repos')).expand_path
end

#sandbox_rootPathname Also known as: project_pods_root


183
184
185
# File 'lib/cocoapods/config.rb', line 183

def sandbox_root
  @sandbox_root ||= installation_root + 'Pods'
end

#silentBool Also known as: silent?


60
61
62
# File 'lib/cocoapods/config.rb', line 60

def silent
  @silent
end

#skip_download_cacheBool Also known as: skip_download_cache?


75
76
77
# File 'lib/cocoapods/config.rb', line 75

def skip_download_cache
  @skip_download_cache
end

#verboseBool


55
56
57
# File 'lib/cocoapods/config.rb', line 55

def verbose
  @verbose
end

Instance Method Details

#default_podfile_pathPathname

Note:

The file is expected to be named Podfile.default

Returns the path of the default Podfile pods.


238
239
240
# File 'lib/cocoapods/config.rb', line 238

def default_podfile_path
  @default_podfile_path ||= templates_dir + 'Podfile.default'
end

#default_test_podfile_pathPathname

Note:

The file is expected to be named Podfile.test

Returns the path of the default Podfile test pods.


248
249
250
# File 'lib/cocoapods/config.rb', line 248

def default_test_podfile_path
  @default_test_podfile_path ||= templates_dir + 'Podfile.test'
end

#home_dirPathname


131
132
133
# File 'lib/cocoapods/config.rb', line 131

def home_dir
  @home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.cocoapods').expand_path
end

#lockfileLockfile, Nil


207
208
209
# File 'lib/cocoapods/config.rb', line 207

def lockfile
  @lockfile ||= Lockfile.from_file(lockfile_path) if lockfile_path
end

#lockfile_pathObject

Note:

The Lockfile is named `Podfile.lock`.

Returns the path of the Lockfile.


228
229
230
# File 'lib/cocoapods/config.rb', line 228

def lockfile_path
  @lockfile_path ||= installation_root + 'Podfile.lock'
end

#podfile_pathPathname, Nil

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.

Returns the path of the Podfile.


220
221
222
# File 'lib/cocoapods/config.rb', line 220

def podfile_path
  @podfile_path ||= podfile_path_in_dir(installation_root)
end

#podfile_path_in_dir(dir) ⇒ Pathname, Nil

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


307
308
309
310
311
312
313
314
315
# File 'lib/cocoapods/config.rb', line 307

def podfile_path_in_dir(dir)
  PODFILE_NAMES.each do |filename|
    candidate = dir + filename
    if candidate.file?
      return candidate
    end
  end
  nil
end

#sandboxSandbox


192
193
194
# File 'lib/cocoapods/config.rb', line 192

def sandbox
  @sandbox ||= Sandbox.new(sandbox_root)
end

#search_index_filePathname


254
255
256
# File 'lib/cocoapods/config.rb', line 254

def search_index_file
  cache_root + 'search_index.json'
end

#sources_managerSource::Manager


145
146
147
148
# File 'lib/cocoapods/config.rb', line 145

def sources_manager
  return @sources_manager if @sources_manager && @sources_manager.repos_dir == repos_dir
  @sources_manager = Source::Manager.new(repos_dir)
end

#templates_dirPathname


152
153
154
# File 'lib/cocoapods/config.rb', line 152

def templates_dir
  @templates_dir ||= Pathname.new(ENV['CP_TEMPLATES_DIR'] || (home_dir + 'templates')).expand_path
end

#verbose?Bool


56
57
58
# File 'lib/cocoapods/config.rb', line 56

def verbose
  @verbose
end

#with_changes(changes) { ... } ⇒ Object

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

Yields:

  • is called while the changes are applied


34
35
36
37
38
39
40
41
42
43
44
# 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