Commit 6943b6d5 authored by Fabio Pelosin + Marin Usalj's avatar Fabio Pelosin + Marin Usalj Committed by Marin Usalj

will introduce convenience methods instead of accessing hash

parent 8928250b
...@@ -6,139 +6,6 @@ module Pod ...@@ -6,139 +6,6 @@ module Pod
autoload :ConfigManager, 'cocoapods/config/config_manager' autoload :ConfigManager, 'cocoapods/config/config_manager'
# 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
#
DEFAULTS = {
:verbose => false,
:silent => false,
:skip_repo_update => false,
:clean => true,
:integrate_targets => true,
:new_version_message => true,
:cache_root => Pathname.new(File.join(ENV['HOME'], 'Library/Caches/CocoaPods')),
:max_cache_size => 500,
:aggressive_cache => false,
}
public
#-------------------------------------------------------------------------#
# @!group UI
# @return [Bool] Whether CocoaPods should provide detailed output about the
# performed actions.
#
attr_accessor :verbose
alias_method :verbose?, :verbose
# @return [Bool] Whether CocoaPods should produce not output.
#
attr_accessor :silent
alias_method :silent?, :silent
# @return [Bool] Whether a message should be printed when a new version of
# CocoaPods is available.
#
attr_accessor :new_version_message
alias_method :new_version_message?, :new_version_message
#-------------------------------------------------------------------------#
# @!group Installation
# @return [Bool] Whether the installer should clean after the installation.
#
attr_accessor :clean
alias_method :clean?, :clean
# @return [Bool] Whether CocoaPods should integrate a user target and build
# the workspace or just create the Pods project.
#
attr_accessor :integrate_targets
alias_method :integrate_targets?, :integrate_targets
# @return [Bool] Whether the installer should skip the repos update.
#
attr_accessor :skip_repo_update
alias_method :skip_repo_update?, :skip_repo_update
public
#-------------------------------------------------------------------------#
# @!group Cache
# @return [Fixnum] The maximum size for the cache expressed in Mb.
#
attr_accessor :max_cache_size
# @return [Pathname] The directory where CocoaPods should cache remote data
# and other expensive to compute information.
#
attr_accessor :cache_root
def cache_root
@cache_root.mkpath unless @cache_root.exist?
@cache_root
end
# Allows to set whether the downloader should use more aggressive caching
# options.
#
# @note The aggressive cache has lead to issues if a tag is updated to
# point to another commit.
#
attr_writer :aggressive_cache
# @return [Bool] Whether the downloader should use more aggressive caching
# options.
#
def aggressive_cache?
@aggressive_cache || (ENV['CP_AGGRESSIVE_CACHE'] == 'TRUE')
end
# def aggressive_cache?
# @aggressive_cache? || (parent.aggressive_cache? if parent)
# end
# pod config verbose true --global
# pod config verbose true
# pod config unset verbose
# pod config get verbose
#
# pod config # defaults to show
#
# ~/.cocoapods/config.yaml
# ~/code/OSS/AwesomeApp/Pods/config.yaml
#
# load the configuration file (path is returned by the manager)
# convert to hash
# user_config? BOOL
# keypath STRING
# value STRING
# manager = Config::ConfigManager.new
# manager.set_local(keypath, value)
# manager.unset_local(keypath)
# manager.set_global(keypath, value)
# manager.unset_global(keypath)
public public
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -357,47 +224,6 @@ module Pod ...@@ -357,47 +224,6 @@ module Pod
# #
# #
LOCAL_OVERRIDES = 'PER_PROJECT_REPO_OVERRIDES'
GLOBAL_OVERRIDES = 'GLOBAL_REPO_OVERRIDES'
def store_global(pod_name, pod_path)
config_hash[GLOBAL_OVERRIDES] ||= {}
config_hash[GLOBAL_OVERRIDES][pod_name] = pod_path
end
def store_local(pod_name, pod_path)
config_hash[LOCAL_OVERRIDES] ||= {}
config_hash[LOCAL_OVERRIDES][project_name] ||= {}
config_hash[LOCAL_OVERRIDES][project_name][pod_name] = pod_path
end
def delete_local(pod_name)
config_hash[LOCAL_OVERRIDES] ||= {}
config_hash[LOCAL_OVERRIDES][project_name].delete(pod_name)
end
def delete_global(pod_name)
config_hash[GLOBAL_OVERRIDES] ||= {}
config_hash[GLOBAL_OVERRIDES].delete(pod_name)
end
def config_hash
@config_hash ||= load_config
end
def load_config
FileUtils.touch(user_settings_file) unless File.exists? user_settings_file
YAML.load(File.open(user_settings_file)) || {}
end
def project_name
`basename #{Dir.pwd}`.chomp
end
def write_config_to_file
File.open(user_settings_file, 'w') { |f| f.write(config_hash.delete_blank.to_yaml) }
end
public public
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
......
...@@ -34,12 +34,9 @@ module Pod ...@@ -34,12 +34,9 @@ module Pod
class NoKeyError < ArgumentError; end class NoKeyError < ArgumentError; end
def initialize()
end
def get_setting(keypath) def get_setting(keypath)
value = global_config[keypath] || DEFAULTS[keypath.to_sym] value = global_config[keypath] || get_environment(keypath) || DEFAULTS[keypath.to_sym]
if value.nil? if value.nil?
raise NoKeyError, "Unrecognized keypath for configuration `#{keypath}`. " \ raise NoKeyError, "Unrecognized keypath for configuration `#{keypath}`. " \
"\nSupported ones are:\n - #{DEFAULTS.keys.join("\n - ")}" "\nSupported ones are:\n - #{DEFAULTS.keys.join("\n - ")}"
...@@ -61,21 +58,15 @@ module Pod ...@@ -61,21 +58,15 @@ module Pod
end end
private
# def set_local(keypath, value) def global_config
# end @global_config ||= load_configuration
# def unset_local(keypath) end
# end
private
def global_config
@global_config ||= load_configuration
end
# @return [Hash] # @return [Hash]
# #
def load_configuration() def load_configuration
if global_config_filepath.exist? if global_config_filepath.exist?
YAML.load_file(global_config_filepath) YAML.load_file(global_config_filepath)
else else
...@@ -89,9 +80,7 @@ module Pod ...@@ -89,9 +80,7 @@ module Pod
File.open(global_config_filepath, 'w') { |f| f.write(yaml) } File.open(global_config_filepath, 'w') { |f| f.write(yaml) }
end end
def set_keypath(keypath, value, hash)
end
# @return [Pathname] The path of the file which contains the user settings. # @return [Pathname] The path of the file which contains the user settings.
# #
def global_config_filepath def global_config_filepath
...@@ -111,6 +100,15 @@ module Pod ...@@ -111,6 +100,15 @@ module Pod
@home_dir ||= Pathname.new("~/.cocoapods").expand_path @home_dir ||= Pathname.new("~/.cocoapods").expand_path
end end
def get_environment(keypath)
value = ENV["CP_#{keypath.upcase}"]
if value == 'TRUE'
true
else
false
end
end
end end
end end
......
...@@ -7,11 +7,13 @@ module Bacon ...@@ -7,11 +7,13 @@ module Bacon
define_method(:run_requirement) do |description, spec| define_method(:run_requirement) do |description, spec|
::Pod::Config.instance = nil ::Pod::Config.instance = nil
::Pod::Config.instance.tap do |c| ::Pod::Config.instance.tap do |c|
c.verbose = false # c.verbose = false
c.silent = true # c.silent = true
# c.skip_repo_update = true
c.repos_dir = fixture('spec-repos') c.repos_dir = fixture('spec-repos')
c.installation_root = SpecHelper.temporary_directory c.installation_root = SpecHelper.temporary_directory
c.skip_repo_update = true
end end
::Pod::UI.output = '' ::Pod::UI.output = ''
......
...@@ -5,14 +5,6 @@ module Pod ...@@ -5,14 +5,6 @@ module Pod
describe Config::ConfigManager do describe Config::ConfigManager do
# manager = Config::ConfigManager.new
# manager.set_local(keypath, value)
# manager.unset_local(keypath)
# manager.set_global(keypath, value)
# manager.unset_global(keypath)
describe "global" do describe "global" do
@config_file_path = temporary_directory + 'config.yaml' @config_file_path = temporary_directory + 'config.yaml'
...@@ -94,6 +86,11 @@ module Pod ...@@ -94,6 +86,11 @@ module Pod
end end
end end
it "can accept aggressive cache from ENV" do
ENV.stubs(:[]).returns('TRUE')
@sut.get_setting('aggressive_cache').should == true
end
xit "it converts string boolean values" xit "it converts string boolean values"
xit "it support keypath" xit "it support keypath"
# key.keypath = 'my value' # key.keypath = 'my value'
...@@ -104,27 +101,6 @@ module Pod ...@@ -104,27 +101,6 @@ module Pod
yaml['verbose'].should == true yaml['verbose'].should == true
end end
xit "works with ENV" do
end
xit "writes global repos without specifying project" do
run_command('config', "--global", pod_name, pod_path)
yaml = YAML.load(File.open(@config_file_path))
yaml[GLOBAL_OVERRIDES][pod_name].should.equal pod_path
end
xit "deletes global configuration" do
run_command('config', "--global", pod_name, pod_path)
run_command('config', "--global", "--delete", pod_name)
yaml = YAML.load(File.open(@config_file_path))
yaml.should.not.has_key? GLOBAL_OVERRIDES
end
end end
end end
...@@ -140,34 +140,6 @@ module Pod ...@@ -140,34 +140,6 @@ module Pod
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
describe "Default settings" do
it "prints out normal information" do
@sut.should.not.be.silent
end
it "does not print verbose information" do
@sut.should.not.be.verbose
end
it "cleans SCM dirs in dependency checkouts" do
@sut.should.clean
end
it "has a default cache size of 500" do
@sut.max_cache_size.should == 500
end
it "returns the cache root" do
@sut.cache_root.should == Pathname.new(File.join(ENV['HOME'], 'Library/Caches/CocoaPods'))
end
it "doesn't use aggressive cache" do
@sut.should.not.aggressive_cache?
end
end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
describe "Dependency Injection" do describe "Dependency Injection" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment