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
7b8c95b4
Commit
7b8c95b4
authored
Sep 19, 2013
by
Marin Usalj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pulled the file stuff to commanc/config
parent
3965697e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
58 deletions
+71
-58
config.rb
lib/cocoapods/command/config.rb
+5
-48
config.rb
lib/cocoapods/config.rb
+61
-4
config_spec.rb
spec/functional/command/config_spec.rb
+3
-4
config_spec.rb
spec/unit/config_spec.rb
+2
-2
No files found.
lib/cocoapods/command/config.rb
View file @
7b8c95b4
...
@@ -16,9 +16,6 @@ module Pod
...
@@ -16,9 +16,6 @@ module Pod
# pod config --delete Kiwi
# pod config --delete Kiwi
#
#
class
Config
<
Command
class
Config
<
Command
CONFIG_FILE_PATH
=
File
.
expand_path
(
'~/.config/cocoapods'
)
LOCAL_OVERRIDES
=
'PER_PROJECT_REPO_OVERRIDES'
GLOBAL_OVERRIDES
=
'GLOBAL_REPO_OVERRIDES'
self
.
summary
=
'Something like `bundle config` ... but better.'
self
.
summary
=
'Something like `bundle config` ... but better.'
self
.
description
=
<<-
DESC
self
.
description
=
<<-
DESC
...
@@ -59,57 +56,17 @@ module Pod
...
@@ -59,57 +56,17 @@ module Pod
def
update_config
def
update_config
if
@should_delete
if
@should_delete
@local
?
delete_local_config
:
delete_global_config
@local
?
config
.
delete_local
(
@pod_name
)
:
config
.
delete_global
(
@pod_name
)
else
else
@local
?
store_local_config
:
store_global_config
@local
?
config
.
store_local
(
@pod_name
,
@pod_path
)
:
config
.
store_global
(
@pod_name
,
@pod_path
)
end
end
write_config_to_file
config
.
write_config_to_file
end
end
def
store_global_
config
def
config
config_hash
[
GLOBAL_OVERRIDES
][
@pod_name
]
=
@pod_path
Pod
::
Config
.
instance
end
end
def
store_local_config
config_hash
[
LOCAL_OVERRIDES
][
project_name
]
||=
{}
config_hash
[
LOCAL_OVERRIDES
][
project_name
][
@pod_name
]
=
@pod_path
end
def
delete_local_config
config_hash
[
LOCAL_OVERRIDES
][
project_name
].
delete
(
@pod_name
)
end
def
delete_global_config
config_hash
[
GLOBAL_OVERRIDES
].
delete
(
@pod_name
)
end
def
config_hash
@config_hash
||=
load_config
end
def
load_config
FileUtils
.
touch
(
CONFIG_FILE_PATH
)
unless
File
.
exists?
CONFIG_FILE_PATH
config
=
YAML
.
load
(
File
.
open
(
CONFIG_FILE_PATH
))
||
{}
config
[
LOCAL_OVERRIDES
]
||=
{}
config
[
GLOBAL_OVERRIDES
]
||=
{}
config
end
end
def
project_name
`basename
#{
Dir
.
pwd
}
`
.
chomp
end
def
write_config_to_file
File
.
open
(
CONFIG_FILE_PATH
,
'w'
)
{
|
f
|
f
.
write
(
config_hash
.
delete_blank
.
to_yaml
)
}
end
end
end
end
class
Hash
def
delete_blank
delete_if
{
|
k
,
v
|
v
.
empty?
or
v
.
instance_of?
(
Hash
)
&&
v
.
delete_blank
.
empty?
}
end
end
end
end
lib/cocoapods/config.rb
View file @
7b8c95b4
...
@@ -113,12 +113,12 @@ module Pod
...
@@ -113,12 +113,12 @@ module Pod
# @!group Initialization
# @!group Initialization
def
initialize
(
use_user_settings
=
true
)
def
initialize
(
use_user_settings
=
true
)
configure_with
(
DEFAULTS
)
if
use_user_settings
&&
user_settings_file
.
exist?
if
use_user_settings
&&
user_settings_file
.
exist?
require
'yaml'
require
'yaml'
user_settings
=
YAML
.
load_file
(
user_settings_file
)
user_settings
=
YAML
.
load_file
(
user_settings_file
)
configure_with
(
user_settings
)
initialize_with
(
user_settings
)
else
initialize_with
(
DEFAULTS
)
end
end
end
end
...
@@ -304,7 +304,7 @@ module Pod
...
@@ -304,7 +304,7 @@ module Pod
#
#
# @return [void]
# @return [void]
#
#
def
configur
e_with
(
values_by_key
)
def
initializ
e_with
(
values_by_key
)
return
unless
values_by_key
return
unless
values_by_key
values_by_key
.
each
do
|
key
,
value
|
values_by_key
.
each
do
|
key
,
value
|
self
.
instance_variable_set
(
"@
#{
key
}
"
,
value
)
self
.
instance_variable_set
(
"@
#{
key
}
"
,
value
)
...
@@ -338,6 +338,56 @@ module Pod
...
@@ -338,6 +338,56 @@ module Pod
nil
nil
end
end
public
#-------------------------------------------------------------------------#
# @!group Local repos
#
#
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
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
...
@@ -370,4 +420,11 @@ module Pod
...
@@ -370,4 +420,11 @@ module Pod
end
end
end
end
end
end
end
class
Hash
def
delete_blank
delete_if
{
|
k
,
v
|
v
.
empty?
or
v
.
instance_of?
(
Hash
)
&&
v
.
delete_blank
.
empty?
}
end
end
end
spec/functional/command/config_spec.rb
View file @
7b8c95b4
...
@@ -14,9 +14,8 @@ module Pod
...
@@ -14,9 +14,8 @@ module Pod
before
do
before
do
Dir
.
stubs
(
:pwd
).
returns
(
'~/code/OSS/SampleProject'
)
Dir
.
stubs
(
:pwd
).
returns
(
'~/code/OSS/SampleProject'
)
@config_file_path
=
temporary_directory
+
"mock_config"
@config_file_path
=
temporary_directory
+
"mock_config.yaml"
Command
::
Config
.
send
(
:remove_const
,
'CONFIG_FILE_PATH'
)
Pod
::
Config
.
instance
.
stubs
(
:user_settings_file
).
returns
(
@config_file_path
)
Command
::
Config
.
const_set
(
"CONFIG_FILE_PATH"
,
@config_file_path
)
end
end
it
"writes local repos for each project"
do
it
"writes local repos for each project"
do
...
@@ -54,7 +53,7 @@ module Pod
...
@@ -54,7 +53,7 @@ module Pod
run_command
(
'config'
,
"--local"
,
pod_name
,
pod_path
)
run_command
(
'config'
,
"--local"
,
pod_name
,
pod_path
)
run_command
(
'config'
,
"--delete"
,
pod_name
)
run_command
(
'config'
,
"--delete"
,
pod_name
)
yaml
=
YAML
.
load
(
File
.
open
(
@config_file_path
))
yaml
=
YAML
.
load
(
File
.
open
(
@config_file_path
))
puts
yaml
yaml
.
should
.
not
.
has_key?
LOCAL_OVERRIDES
yaml
.
should
.
not
.
has_key?
LOCAL_OVERRIDES
yaml
[
GLOBAL_OVERRIDES
][
pod_name
].
should
.
equal
pod_path
yaml
[
GLOBAL_OVERRIDES
][
pod_name
].
should
.
equal
pod_path
end
end
...
...
spec/unit/config_spec.rb
View file @
7b8c95b4
...
@@ -196,9 +196,9 @@ module Pod
...
@@ -196,9 +196,9 @@ module Pod
@sut
.
send
(
:user_settings_file
).
should
==
Pathname
.
new
(
"~/.cocoapods/config.yaml"
).
expand_path
@sut
.
send
(
:user_settings_file
).
should
==
Pathname
.
new
(
"~/.cocoapods/config.yaml"
).
expand_path
end
end
it
"can be
configur
ed with a hash"
do
it
"can be
initializ
ed with a hash"
do
hash
=
{
:verbose
=>
true
}
hash
=
{
:verbose
=>
true
}
@sut
.
send
(
:
configur
e_with
,
hash
)
@sut
.
send
(
:
initializ
e_with
,
hash
)
@sut
.
should
.
be
.
verbose
@sut
.
should
.
be
.
verbose
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