From 67e6900b53c0edaff49cab05d249282b36d0eb11 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Tue, 15 Mar 2016 13:33:21 +0000 Subject: [PATCH] Implemented downloader. --- lib/cocoapods-deploy/deploy_downloader.rb | 20 +++++++++++++++----- spec/deploy_downloader_spec.rb | 18 +----------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/cocoapods-deploy/deploy_downloader.rb b/lib/cocoapods-deploy/deploy_downloader.rb index c150540..c594a67 100644 --- a/lib/cocoapods-deploy/deploy_downloader.rb +++ b/lib/cocoapods-deploy/deploy_downloader.rb @@ -16,22 +16,32 @@ def download(config) end def download_source(config) - # TODO: Method for looping through dependency source = ExternalSources.from_dependency(dependency, config.podfile.defined_in_file) - source.fetch(config.sandbox) + source.fetch end def download_podspec(config) dependencies_for_sources(config).each do |dep| + puts "woo #{dep}" source = ExternalSources.from_dependency(dep, config.podfile.defined_in_file) - source.fetch(config.sandbox) + source.fetch end end - private + def podfile_sources(config) + return ["https://github.com/CocoaPods/CocoaPods.git"] if config.podfile.sources.empty? + return config.podfile.sources + end def dependencies_for_sources(config) - [] + podfile_sources(config).map do |source| + filename = File.basename(source, ".*") + raw_url = File.join( File.dirname(source), filename ) + root_url = "#{raw_url}/raw" + source = @dependency.external_source[:podspec].gsub('{root-url}', root_url) + + Dependency.new(@dependency.name, {:podspec => source}) + end end end end diff --git a/spec/deploy_downloader_spec.rb b/spec/deploy_downloader_spec.rb index 966ebb5..b8c697f 100644 --- a/spec/deploy_downloader_spec.rb +++ b/spec/deploy_downloader_spec.rb @@ -16,13 +16,13 @@ module Pod Config.instance.stubs(:podfile).returns(@podfile) @source = MockExternalSource.new + ExternalSources.stubs(:from_dependency).returns(@source) end it "should external source outside of repo" do dependency = Dependency.new("AFNetworking", { :git => "https://github.com/gowalla/AFNetworking.git"}) downloader = DeployDownloader.new(dependency) - ExternalSources.stubs(:from_dependency).returns(@source) @source.expects(:fetch) downloader.download(Config.instance) @@ -31,24 +31,8 @@ module Pod it "should download source from main repo" do dependency = Dependency.new("AFNetworking", { :podspec => "{root-url}/master/Specs/AFNetworking/1.0/AFNetworking.podspec.json"}) downloader = DeployDownloader.new(dependency) - expected_dependency = Dependency.new("AFNetworking", { :podspec => "http://github.com/My/Repo.git/master/Specs/AFNetworking/1.0/AFNetworking.podspec.json"}) - ExternalSources.expects(:from_dependency).with(expected_dependency, @podfile.defined_in_file) ExternalSources.stubs(:from_dependency).returns(@source) - @source.expects(:fetch) - - downloader.download(Config.instance) - end - - it "should download source from external repo" do - dependency = Dependency.new("AFNetworking", { :podspec => "{root-url}/master/Specs/AFNetworking/1.0/AFNetworking.podspec.json"}) - downloader = DeployDownloader.new(dependency) - expected_dependency = Dependency.new("AFNetworking", { :podspec => "http://github.com/CocoaPods/Specs.git/master/Specs/AFNetworking/1.0/AFNetworking.podspec.json"}) - - ExternalSources.expects(:from_dependency).with(expected_dependency, @podfile.defined_in_file) - ExternalSources.stubs(:from_dependency).returns(@source) - @source.expects(:fetch) - downloader.download(Config.instance) end end