Commit 57a3cae6 authored by Fabio Pelosin's avatar Fabio Pelosin

[ExternalSources] Minor cleanup

parent b25d4110
......@@ -79,23 +79,6 @@ module Pod
public
# @!group Fetching
# Fetches the external source from the remote according to the params.
#
# @param [Sandbox] sandbox
# the sandbox where the specification should be stored.
#
# @return [void]
#
def fetch(sandbox)
raise "Abstract method"
end
#--------------------------------------#
public
# @!group Subclasses hooks
# Fetches the external source from the remote according to the params.
......@@ -117,6 +100,26 @@ module Pod
#--------------------------------------#
protected
# @return [String] The uri of the podspec appending the name of the file
# and expanding it if necessary.
#
# @note If the declared path is expanded only if the represents a path
# relative to the file system.
#
def normalized_podspec_path(declared_path)
if File.extname(declared_path) == '.podspec'
path_with_ext = declared_path
else
path_with_ext = "#{declared_path}/#{name}.podspec"
end
podfile_dir = File.dirname(podfile_path || '')
File.expand_path(path_with_ext, podfile_dir)
end
#--------------------------------------#
private
# @! Subclasses helpers
......@@ -174,7 +177,6 @@ module Pod
def store_podspec(sandbox, spec)
sandbox.store_podspec(name, spec, true)
end
end
#-------------------------------------------------------------------------#
......@@ -217,7 +219,8 @@ module Pod
# @see AbstractExternalSource#fetch
#
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'
open(podspec_uri) { |io| store_podspec(sandbox, io.read) }
end
......@@ -229,8 +232,6 @@ module Pod
"from `#{params[:podspec]}`"
end
#--------------------------------------#
private
# @!group Helpers
......@@ -246,10 +247,7 @@ module Pod
if declared_path.match(%r{^.+://})
declared_path
else
path_with_ext = File.extname(declared_path) == '.podspec' ? declared_path : "#{declared_path}/#{name}.podspec"
podfile_dir = File.dirname(podfile_path || '')
absolute_path = File.expand_path(path_with_ext, podfile_dir)
absolute_path
normalized_podspec_path(declared_path)
end
end
end
......@@ -266,11 +264,16 @@ module Pod
# @see AbstractExternalSource#fetch
#
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
unless podspec.exist?
raise Informative, "No podspec found for `#{name}` in " \
"`#{declared_path}`"
end
store_podspec(sandbox, podspec)
path_is_absolute_or_rooted_to_home = declared_path.absolute? || declared_path.to_s.start_with?('~')
sandbox.store_local_path(name, podspec.dirname, path_is_absolute_or_rooted_to_home)
is_absolute = absolute?(podspec)
sandbox.store_local_path(name, podspec.dirname, is_absolute)
end
end
......@@ -280,30 +283,27 @@ module Pod
"from `#{params[:path] || params[:local]}`"
end
#--------------------------------------#
private
# @!group Helpers
# @return [Pathname] the path as declared in the podspec
# @return [String] The path as declared by the user.
#
def declared_path
Pathname.new params[:path] || params[:local]
result = params[:path] || params[:local]
result.to_s if result
end
# @return [Pathname] the path of the podspec.
# @return [Pathname] The absolute path of the podspec.
#
def podspec_path
path_with_ext = File.extname(declared_path) == '.podspec' ? declared_path : "#{declared_path}/#{name}.podspec"
podfile_dir = File.dirname(podfile_path || '')
absolute_path = File.expand_path(path_with_ext, podfile_dir)
pathname = Pathname.new(absolute_path)
Pathname(normalized_podspec_path(declared_path))
end
unless pathname.exist?
raise Informative, "No podspec found for `#{name}` in `#{declared_path}`"
end
pathname
# @return [Bool]
#
def absolute?(path)
Pathname(path).absolute? || path.to_s.start_with?('~')
end
end
......
......@@ -161,6 +161,7 @@ module Pod
end
it "expands the tilde" do
File.stubs(:exist?).returns(true)
@subject.stubs(:params).returns(:podspec => '~/Reachability')
path = @subject.send(:podspec_uri)
path.should == ENV['HOME'] + '/Reachability/Reachability.podspec'
......@@ -179,8 +180,8 @@ module Pod
describe ExternalSources::PathSource do
before do
podspec_path = fixture('integration/Reachability/Reachability.podspec')
dependency = Dependency.new("Reachability", :path => fixture('integration/Reachability'))
params = { :path => fixture('integration/Reachability') }
dependency = Dependency.new("Reachability", params)
podfile_path = fixture('integration/Podfile')
@subject = ExternalSources.from_dependency(dependency, podfile_path)
end
......@@ -191,11 +192,12 @@ module Pod
path.should.exist?
end
it "creates a copy of the podspec [Deprecated local option]" do
dependency = Dependency.new("Reachability", :local => fixture('integration/Reachability'))
it "supports the deprecated local key" do
params = { :local => fixture('integration/Reachability') }
dependency = Dependency.new("Reachability", params)
podfile_path = fixture('integration/Podfile')
external_source = ExternalSources.from_dependency(dependency, podfile_path)
external_source.fetch(config.sandbox)
@subject = ExternalSources.from_dependency(dependency, podfile_path)
@subject.fetch(config.sandbox)
path = config.sandbox.root + 'Local Podspecs/Reachability.podspec'
path.should.exist?
end
......@@ -211,6 +213,13 @@ module Pod
}
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
it "handles absolute paths" do
......@@ -233,17 +242,13 @@ module Pod
end
it "expands the tilde" do
File.stubs(:exist?).returns(true)
@subject.stubs(:params).returns(:path => '~/Reachability')
Pathname.any_instance.stubs(:exist?).returns(true)
path = @subject.send(:podspec_path)
path.should == Pathname(ENV['HOME']) + 'Reachability/Reachability.podspec'
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
......
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