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
57a3cae6
Commit
57a3cae6
authored
Apr 15, 2014
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ExternalSources] Minor cleanup
parent
b25d4110
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
51 deletions
+56
-51
external_sources.rb
lib/cocoapods/external_sources.rb
+40
-40
external_sources_spec.rb
spec/unit/external_sources_spec.rb
+16
-11
No files found.
lib/cocoapods/external_sources.rb
View file @
57a3cae6
...
@@ -79,7 +79,7 @@ module Pod
...
@@ -79,7 +79,7 @@ module Pod
public
public
# @!group
Fetching
# @!group
Subclasses hooks
# Fetches the external source from the remote according to the params.
# Fetches the external source from the remote according to the params.
#
#
...
@@ -92,27 +92,30 @@ module Pod
...
@@ -92,27 +92,30 @@ module Pod
raise
"Abstract method"
raise
"Abstract method"
end
end
#--------------------------------------#
# @return [String] a string representation of the source suitable for UI.
#
def
description
raise
"Abstract method"
end
public
#--------------------------------------#
# @!group Subclasses hooks
protected
# Fetches the external source from the remote according to the params.
# @return [String] The uri of the podspec appending the name of the file
#
# and expanding it if necessary.
# @param [Sandbox] sandbox
# the sandbox where the specification should be stored.
#
#
# @return [void]
# @note If the declared path is expanded only if the represents a path
# relative to the file system.
#
#
def
fetch
(
sandbox
)
def
normalized_podspec_path
(
declared_path
)
raise
"Abstract method"
if
File
.
extname
(
declared_path
)
==
'.podspec'
path_with_ext
=
declared_path
else
path_with_ext
=
"
#{
declared_path
}
/
#{
name
}
.podspec"
end
end
podfile_dir
=
File
.
dirname
(
podfile_path
||
''
)
# @return [String] a string representation of the source suitable for UI.
File
.
expand_path
(
path_with_ext
,
podfile_dir
)
#
def
description
raise
"Abstract method"
end
end
#--------------------------------------#
#--------------------------------------#
...
@@ -174,7 +177,6 @@ module Pod
...
@@ -174,7 +177,6 @@ module Pod
def
store_podspec
(
sandbox
,
spec
)
def
store_podspec
(
sandbox
,
spec
)
sandbox
.
store_podspec
(
name
,
spec
,
true
)
sandbox
.
store_podspec
(
name
,
spec
,
true
)
end
end
end
end
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
...
@@ -217,7 +219,8 @@ module Pod
...
@@ -217,7 +219,8 @@ module Pod
# @see AbstractExternalSource#fetch
# @see AbstractExternalSource#fetch
#
#
def
fetch
(
sandbox
)
def
fetch
(
sandbox
)
UI
.
titled_section
(
"Fetching podspec for `
#{
name
}
`
#{
description
}
"
,
{
:verbose_prefix
=>
"-> "
})
do
title
=
"Fetching podspec for `
#{
name
}
`
#{
description
}
"
UI
.
titled_section
(
title
,
{
:verbose_prefix
=>
"-> "
})
do
require
'open-uri'
require
'open-uri'
open
(
podspec_uri
)
{
|
io
|
store_podspec
(
sandbox
,
io
.
read
)
}
open
(
podspec_uri
)
{
|
io
|
store_podspec
(
sandbox
,
io
.
read
)
}
end
end
...
@@ -229,8 +232,6 @@ module Pod
...
@@ -229,8 +232,6 @@ module Pod
"from `
#{
params
[
:podspec
]
}
`"
"from `
#{
params
[
:podspec
]
}
`"
end
end
#--------------------------------------#
private
private
# @!group Helpers
# @!group Helpers
...
@@ -246,10 +247,7 @@ module Pod
...
@@ -246,10 +247,7 @@ module Pod
if
declared_path
.
match
(
%r{^.+://}
)
if
declared_path
.
match
(
%r{^.+://}
)
declared_path
declared_path
else
else
path_with_ext
=
File
.
extname
(
declared_path
)
==
'.podspec'
?
declared_path
:
"
#{
declared_path
}
/
#{
name
}
.podspec"
normalized_podspec_path
(
declared_path
)
podfile_dir
=
File
.
dirname
(
podfile_path
||
''
)
absolute_path
=
File
.
expand_path
(
path_with_ext
,
podfile_dir
)
absolute_path
end
end
end
end
end
end
...
@@ -266,11 +264,16 @@ module Pod
...
@@ -266,11 +264,16 @@ module Pod
# @see AbstractExternalSource#fetch
# @see AbstractExternalSource#fetch
#
#
def
fetch
(
sandbox
)
def
fetch
(
sandbox
)
UI
.
titled_section
(
"Fetching podspec for `
#{
name
}
`
#{
description
}
"
,
{
:verbose_prefix
=>
"-> "
})
do
title
=
"Fetching podspec for `
#{
name
}
`
#{
description
}
"
UI
.
titled_section
(
title
,
{
:verbose_prefix
=>
"-> "
})
do
podspec
=
podspec_path
podspec
=
podspec_path
unless
podspec
.
exist?
raise
Informative
,
"No podspec found for `
#{
name
}
` in "
\
"`
#{
declared_path
}
`"
end
store_podspec
(
sandbox
,
podspec
)
store_podspec
(
sandbox
,
podspec
)
path_is_absolute_or_rooted_to_home
=
declared_path
.
absolute?
||
declared_path
.
to_s
.
start_with?
(
'~'
)
is_absolute
=
absolute?
(
podspec
)
sandbox
.
store_local_path
(
name
,
podspec
.
dirname
,
path_is_absolute_or_rooted_to_hom
e
)
sandbox
.
store_local_path
(
name
,
podspec
.
dirname
,
is_absolut
e
)
end
end
end
end
...
@@ -280,30 +283,27 @@ module Pod
...
@@ -280,30 +283,27 @@ module Pod
"from `
#{
params
[
:path
]
||
params
[
:local
]
}
`"
"from `
#{
params
[
:path
]
||
params
[
:local
]
}
`"
end
end
#--------------------------------------#
private
private
# @!group Helpers
# @!group Helpers
# @return [
Pathname] the path as declared in the podspec
# @return [
String] The path as declared by the user.
#
#
def
declared_path
def
declared_path
Pathname
.
new
params
[
:path
]
||
params
[
:local
]
result
=
params
[
:path
]
||
params
[
:local
]
result
.
to_s
if
result
end
end
# @return [Pathname]
th
e path of the podspec.
# @return [Pathname]
The absolut
e path of the podspec.
#
#
def
podspec_path
def
podspec_path
path_with_ext
=
File
.
extname
(
declared_path
)
==
'.podspec'
?
declared_path
:
"
#{
declared_path
}
/
#{
name
}
.podspec"
Pathname
(
normalized_podspec_path
(
declared_path
))
podfile_dir
=
File
.
dirname
(
podfile_path
||
''
)
absolute_path
=
File
.
expand_path
(
path_with_ext
,
podfile_dir
)
pathname
=
Pathname
.
new
(
absolute_path
)
unless
pathname
.
exist?
raise
Informative
,
"No podspec found for `
#{
name
}
` in `
#{
declared_path
}
`"
end
end
pathname
# @return [Bool]
#
def
absolute?
(
path
)
Pathname
(
path
).
absolute?
||
path
.
to_s
.
start_with?
(
'~'
)
end
end
end
end
...
...
spec/unit/external_sources_spec.rb
View file @
57a3cae6
...
@@ -161,6 +161,7 @@ module Pod
...
@@ -161,6 +161,7 @@ module Pod
end
end
it
"expands the tilde"
do
it
"expands the tilde"
do
File
.
stubs
(
:exist?
).
returns
(
true
)
@subject
.
stubs
(
:params
).
returns
(
:podspec
=>
'~/Reachability'
)
@subject
.
stubs
(
:params
).
returns
(
:podspec
=>
'~/Reachability'
)
path
=
@subject
.
send
(
:podspec_uri
)
path
=
@subject
.
send
(
:podspec_uri
)
path
.
should
==
ENV
[
'HOME'
]
+
'/Reachability/Reachability.podspec'
path
.
should
==
ENV
[
'HOME'
]
+
'/Reachability/Reachability.podspec'
...
@@ -179,8 +180,8 @@ module Pod
...
@@ -179,8 +180,8 @@ module Pod
describe
ExternalSources
::
PathSource
do
describe
ExternalSources
::
PathSource
do
before
do
before
do
p
odspec_path
=
fixture
(
'integration/Reachability/Reachability.podspec'
)
p
arams
=
{
:path
=>
fixture
(
'integration/Reachability'
)
}
dependency
=
Dependency
.
new
(
"Reachability"
,
:path
=>
fixture
(
'integration/Reachability'
)
)
dependency
=
Dependency
.
new
(
"Reachability"
,
params
)
podfile_path
=
fixture
(
'integration/Podfile'
)
podfile_path
=
fixture
(
'integration/Podfile'
)
@subject
=
ExternalSources
.
from_dependency
(
dependency
,
podfile_path
)
@subject
=
ExternalSources
.
from_dependency
(
dependency
,
podfile_path
)
end
end
...
@@ -191,11 +192,12 @@ module Pod
...
@@ -191,11 +192,12 @@ module Pod
path
.
should
.
exist?
path
.
should
.
exist?
end
end
it
"creates a copy of the podspec [Deprecated local option]"
do
it
"supports the deprecated local key"
do
dependency
=
Dependency
.
new
(
"Reachability"
,
:local
=>
fixture
(
'integration/Reachability'
))
params
=
{
:local
=>
fixture
(
'integration/Reachability'
)
}
dependency
=
Dependency
.
new
(
"Reachability"
,
params
)
podfile_path
=
fixture
(
'integration/Podfile'
)
podfile_path
=
fixture
(
'integration/Podfile'
)
external_source
=
ExternalSources
.
from_dependency
(
dependency
,
podfile_path
)
@subject
=
ExternalSources
.
from_dependency
(
dependency
,
podfile_path
)
external_source
.
fetch
(
config
.
sandbox
)
@subject
.
fetch
(
config
.
sandbox
)
path
=
config
.
sandbox
.
root
+
'Local Podspecs/Reachability.podspec'
path
=
config
.
sandbox
.
root
+
'Local Podspecs/Reachability.podspec'
path
.
should
.
exist?
path
.
should
.
exist?
end
end
...
@@ -211,6 +213,13 @@ module Pod
...
@@ -211,6 +213,13 @@ module Pod
}
}
end
end
it
"raises if the podspec cannot be found"
do
@subject
.
stubs
(
:params
).
returns
(
:path
=>
temporary_directory
)
should
.
raise
Informative
do
@subject
.
fetch
(
config
.
sandbox
)
end
.
message
.
should
.
match
/No podspec found for `Reachability` in `
#{
temporary_directory
}
`/
end
describe
"Helpers"
do
describe
"Helpers"
do
it
"handles absolute paths"
do
it
"handles absolute paths"
do
...
@@ -233,17 +242,13 @@ module Pod
...
@@ -233,17 +242,13 @@ module Pod
end
end
it
"expands the tilde"
do
it
"expands the tilde"
do
File
.
stubs
(
:exist?
).
returns
(
true
)
@subject
.
stubs
(
:params
).
returns
(
:path
=>
'~/Reachability'
)
@subject
.
stubs
(
:params
).
returns
(
:path
=>
'~/Reachability'
)
Pathname
.
any_instance
.
stubs
(
:exist?
).
returns
(
true
)
Pathname
.
any_instance
.
stubs
(
:exist?
).
returns
(
true
)
path
=
@subject
.
send
(
:podspec_path
)
path
=
@subject
.
send
(
:podspec_path
)
path
.
should
==
Pathname
(
ENV
[
'HOME'
])
+
'Reachability/Reachability.podspec'
path
.
should
==
Pathname
(
ENV
[
'HOME'
])
+
'Reachability/Reachability.podspec'
end
end
it
"raises if the podspec cannot be found"
do
@subject
.
stubs
(
:params
).
returns
(
:path
=>
temporary_directory
)
e
=
lambda
{
@subject
.
send
(
:podspec_path
)
}.
should
.
raise
Informative
e
.
message
.
should
.
match
/No podspec found for `Reachability` in `
#{
temporary_directory
}
`/
end
end
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