Eagerly set the download strategy
This commit is contained in:
parent
de42ad52a5
commit
771bc2978c
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user