Eagerly set the download strategy

This commit is contained in:
Jack Nagel 2014-07-15 13:42:03 -05:00
parent de42ad52a5
commit 771bc2978c
3 changed files with 9 additions and 6 deletions

View File

@ -9,7 +9,8 @@ class Resource
include FileUtils
attr_reader :checksum, :mirrors, :specs, :using
attr_writer :url, :checksum, :version, :download_strategy
attr_writer :url, :checksum, :version
attr_accessor :download_strategy
# Formula name must be set after the DSL, as we have no access to the
# formula name before initialization of the formula
@ -34,10 +35,6 @@ class Resource
name.nil? ? owner.name : "#{owner.name}--#{name}"
end
def download_strategy
@download_strategy ||= DownloadStrategyDetector.detect(url, using)
end
def cached_download
downloader.cached_location
end
@ -104,6 +101,7 @@ class Resource
@url = val
@specs.merge!(specs)
@using = @specs.delete(:using)
@download_strategy = DownloadStrategyDetector.detect(url, using)
end
def version val=nil

View File

@ -128,7 +128,8 @@ class DependencyCollectorTests < Homebrew::TestCase
def test_resource_dep_raises_for_unknown_classes
resource = Resource.new
resource.url "foo", :using => Class.new
resource.url "foo"
resource.download_strategy = Class.new
assert_raises(TypeError) { @d.add(resource) }
end
end

View File

@ -38,6 +38,10 @@ class ResourceTests < Homebrew::TestCase
assert_equal GitDownloadStrategy, @resource.download_strategy
end
def test_raises_for_unknown_download_strategy_class
assert_raises(TypeError) { @resource.url("foo", :using => Class.new) }
end
def test_does_not_mutate_specs_hash
specs = { :using => :git, :branch => 'master' }
@resource.url('foo', specs)