Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
8928250b
Commit
8928250b
authored
Sep 19, 2013
by
Fabio Pelosin + Marin Usalj
Committed by
Marin Usalj
Oct 11, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started rewriting config class
parent
7b8c95b4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
305 additions
and
43 deletions
+305
-43
config.rb
lib/cocoapods/config.rb
+44
-34
config_manager.rb
lib/cocoapods/config/config_manager.rb
+118
-0
config_spec.rb
spec/functional/command/config_spec.rb
+13
-9
config_manager_spec.rb
spec/unit/config/config_manager_spec.rb
+130
-0
No files found.
lib/cocoapods/config.rb
View file @
8928250b
...
...
@@ -4,6 +4,8 @@ module Pod
#
class
Config
autoload
:ConfigManager
,
'cocoapods/config/config_manager'
# The default settings for the configuration.
#
# Users can specify custom settings in `~/.cocoapods/config.yaml`.
...
...
@@ -106,19 +108,54 @@ module Pod
@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
#-------------------------------------------------------------------------#
# @!group Initialization
def
initialize
(
use_user_settings
=
true
)
if
use_user_settings
&&
user_settings_file
.
exist?
require
'yaml'
user_settings
=
YAML
.
load_file
(
user_settings_file
)
initialize_with
(
user_settings
)
else
initialize_with
(
DEFAULTS
)
# 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]
#
def
initialize
(
settings
=
{})
settings
.
each
do
|
key
,
value
|
self
.
instance_variable_set
(
"@
#{
key
}
"
,
value
)
end
end
...
...
@@ -132,13 +169,6 @@ module Pod
# @!group Paths
# @return [Pathname] the directory where repos, templates and configuration
# files are stored.
#
def
home_dir
@home_dir
||=
Pathname
.
new
(
ENV
[
'CP_HOME_DIR'
]
||
"~/.cocoapods"
).
expand_path
end
# @return [Pathname] the directory where the CocoaPods sources are stored.
#
def
repos_dir
...
...
@@ -291,26 +321,6 @@ module Pod
# @!group Private helpers
# @return [Pathname] The path of the file which contains the user settings.
#
def
user_settings_file
home_dir
+
"config.yaml"
end
# 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]
#
def
initialize_with
(
values_by_key
)
return
unless
values_by_key
values_by_key
.
each
do
|
key
,
value
|
self
.
instance_variable_set
(
"@
#{
key
}
"
,
value
)
end
end
# @return [Array<String>] The filenames that the Podfile can have ordered
# by priority.
#
...
...
lib/cocoapods/config/config_manager.rb
0 → 100644
View file @
8928250b
module
Pod
class
Config
require
'yaml'
# The config manager is responsible for reading and writing the config.yaml
# file.
#
class
ConfigManager
# 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
,
}
class
NoKeyError
<
ArgumentError
;
end
def
initialize
()
end
def
get_setting
(
keypath
)
value
=
global_config
[
keypath
]
||
DEFAULTS
[
keypath
.
to_sym
]
if
value
.
nil?
raise
NoKeyError
,
"Unrecognized keypath for configuration `
#{
keypath
}
`. "
\
"
\n
Supported ones are:
\n
-
#{
DEFAULTS
.
keys
.
join
(
"
\n
- "
)
}
"
end
value
end
def
set_global
(
keypath
,
value
)
hash
=
load_configuration
if
value
==
'true'
value
=
true
end
hash
[
keypath
]
=
value
store_configuration
(
hash
)
end
def
unset_global
(
keypath
)
end
# def set_local(keypath, value)
# end
# def unset_local(keypath)
# end
private
def
global_config
@global_config
||=
load_configuration
end
# @return [Hash]
#
def
load_configuration
()
if
global_config_filepath
.
exist?
YAML
.
load_file
(
global_config_filepath
)
else
Hash
.
new
end
end
def
store_configuration
(
hash
)
yaml
=
YAML
.
dump
(
hash
)
global_config_filepath
File
.
open
(
global_config_filepath
,
'w'
)
{
|
f
|
f
.
write
(
yaml
)
}
end
def
set_keypath
(
keypath
,
value
,
hash
)
end
# @return [Pathname] The path of the file which contains the user settings.
#
def
global_config_filepath
home_dir
+
"config.yaml"
end
def
local_config_filepath
end
# @return [Pathname] the directory where repos, templates and configuration
# files are stored.
#
def
home_dir
# TODO: test ENV
# @home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || "~/.cocoapods").expand_path
@home_dir
||=
Pathname
.
new
(
"~/.cocoapods"
).
expand_path
end
end
end
end
spec/functional/command/config_spec.rb
View file @
8928250b
...
...
@@ -12,12 +12,13 @@ module Pod
project_name
=
'SampleProject'
before
do
Dir
.
stubs
(
:pwd
).
returns
(
'~/code/OSS/SampleProject'
)
#
Dir.stubs(:pwd).returns('~/code/OSS/SampleProject')
@config_file_path
=
temporary_directory
+
"mock_config.yaml"
Pod
::
Config
.
instance
.
stubs
(
:user_settings_file
).
returns
(
@config_file_path
)
end
it
"writes local repos for each project"
do
run_command
(
'config'
,
"--local"
,
pod_name
,
pod_path
)
yaml
=
YAML
.
load
(
File
.
open
(
@config_file_path
))
...
...
@@ -32,6 +33,16 @@ module Pod
yaml
[
GLOBAL_OVERRIDES
][
pod_name
].
should
.
equal
pod_path
end
it
"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
it
"defaults to local scope"
do
run_command
(
'config'
,
pod_name
,
pod_path
)
yaml
=
YAML
.
load
(
File
.
open
(
@config_file_path
))
...
...
@@ -48,7 +59,7 @@ module Pod
].
each
{
|
invalid
|
invalid
.
should
.
raise
CLAide
::
Help
}
end
it
"deletes local configuration by default"
do
x
it
"deletes local configuration by default"
do
run_command
(
'config'
,
"--global"
,
pod_name
,
pod_path
)
run_command
(
'config'
,
"--local"
,
pod_name
,
pod_path
)
run_command
(
'config'
,
"--delete"
,
pod_name
)
...
...
@@ -58,13 +69,6 @@ module Pod
yaml
[
GLOBAL_OVERRIDES
][
pod_name
].
should
.
equal
pod_path
end
it
"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
...
...
spec/unit/config/config_manager_spec.rb
0 → 100644
View file @
8928250b
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
require
'yaml'
module
Pod
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
@config_file_path
=
temporary_directory
+
'config.yaml'
before
do
@sut
=
Config
::
ConfigManager
.
new
@sut
.
stubs
(
:home_dir
).
returns
(
temporary_directory
)
end
it
"creates a global config file if one didn't exist"
do
FileUtils
.
rm_rf
(
@config_file_path
)
@sut
.
set_global
(
'verbose'
,
'true'
)
@config_file_path
.
should
.
exist
end
it
"stores a global setting"
do
@sut
.
set_global
(
'verbose'
,
'true'
)
yaml
=
YAML
.
load_file
(
@config_file_path
)
yaml
[
'verbose'
].
should
==
true
end
it
"preserves the existing settings of the configuration file"
do
@sut
.
set_global
(
'user_name'
,
'Super Marin'
)
@sut
.
set_global
(
'verbose'
,
'true'
)
yaml
=
YAML
.
load_file
(
@config_file_path
)
yaml
[
'user_name'
].
should
==
'Super Marin'
end
xit
"allows to store a development pod"
do
@sut
.
set_global
(
'development.ObjectiveSugar'
,
'~/code/OS'
)
yaml
=
YAML
.
load_file
(
@config_file_path
)
yaml
[
'development.ObjectiveSugar'
].
should
==
'~/code/OS'
end
it
"returns a globally decided setting"
do
@sut
.
set_global
(
'user_name'
,
'Super Marin'
)
@sut
.
get_setting
(
'user_name'
).
should
==
'Super Marin'
end
it
"verbose by default is false"
do
@sut
.
get_setting
(
'verbose'
).
should
==
false
end
it
"silent by default is false"
do
@sut
.
get_setting
(
'silent'
).
should
==
false
end
it
"skips repo update by default is false"
do
@sut
.
get_setting
(
'skip_repo_update'
).
should
==
false
end
it
"clean by default is true"
do
@sut
.
get_setting
(
'clean'
).
should
==
true
end
it
"integrate_targets by default is true"
do
@sut
.
get_setting
(
'integrate_targets'
).
should
==
true
end
it
"new_version_message by default is true"
do
@sut
.
get_setting
(
'new_version_message'
).
should
==
true
end
it
"cache_root returns the cache root by default"
do
@sut
.
get_setting
(
'cache_root'
).
to_s
.
should
.
include
(
'Library/Caches/CocoaPods'
)
end
it
"max_cache_size is 500 MB by default"
do
@sut
.
get_setting
(
'max_cache_size'
).
should
==
500
end
it
"aggressive_cache is false by default"
do
@sut
.
get_setting
(
'aggressive_cache'
).
should
==
false
end
it
"raises if there is an attempt to access an unrecognized attribute"
do
should
.
raise
Config
::
ConfigManager
::
NoKeyError
do
@sut
.
get_setting
(
'idafjaeilfjoasijfopasdj'
)
end
end
xit
"it converts string boolean values"
xit
"it support keypath"
# key.keypath = 'my value'
end
xit
"writes local repos for each project"
do
@sut
.
set_local
(
'verbose'
,
'true'
)
yaml
[
'verbose'
].
should
==
true
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment