Avoid nil in URL specs

This commit is contained in:
Jack Nagel 2013-02-11 20:50:52 -06:00
parent e22af69149
commit 248891fde1
4 changed files with 10 additions and 17 deletions

View File

@ -4,13 +4,7 @@ require 'vendor/multi_json'
class AbstractDownloadStrategy class AbstractDownloadStrategy
def initialize name, package def initialize name, package
@url = package.url @url = package.url
@specs = package.specs @spec, @ref = package.specs.dup.shift
case @specs
when Hash
@spec = @specs.keys.first # only use first spec
@ref = @specs.values.first
end
end end
def expand_safe_system_args args def expand_safe_system_args args

View File

@ -698,7 +698,7 @@ private
@build ||= BuildOptions.new(ARGV.options_only) @build ||= BuildOptions.new(ARGV.options_only)
end end
def url val=nil, specs=nil def url val=nil, specs={}
if val.nil? if val.nil?
return @stable.url if @stable return @stable.url if @stable
return @url if @url return @url if @url
@ -724,7 +724,7 @@ private
@devel.instance_eval(&block) @devel.instance_eval(&block)
end end
def head val=nil, specs=nil def head val=nil, specs={}
return @head if val.nil? return @head if val.nil?
@head ||= HeadSoftwareSpec.new @head ||= HeadSoftwareSpec.new
@head.url(val, specs) @head.url(val, specs)

View File

@ -9,6 +9,7 @@ class SoftwareSpec
@url = url @url = url
@version = version @version = version
@mirrors = [] @mirrors = []
@specs = {}
end end
def download_strategy def download_strategy
@ -42,13 +43,11 @@ class SoftwareSpec
} }
end end
def url val=nil, specs=nil def url val=nil, specs={}
return @url if val.nil? return @url if val.nil?
@url = val @url = val
unless specs.nil? @using = specs.delete(:using)
@using = specs.delete :using @specs.merge!(specs)
@specs = specs
end
end end
def version val=nil def version val=nil

View File

@ -82,9 +82,9 @@ class FormulaTests < Test::Unit::TestCase
assert_equal 'file:///foo.com/testball-0.2.tbz', f.devel.url assert_equal 'file:///foo.com/testball-0.2.tbz', f.devel.url
assert_equal 'https://github.com/mxcl/homebrew.git', f.head.url assert_equal 'https://github.com/mxcl/homebrew.git', f.head.url
assert_nil f.stable.specs assert_empty f.stable.specs
assert_nil f.bottle.specs assert_empty f.bottle.specs
assert_nil f.devel.specs assert_empty f.devel.specs
assert_equal({ :tag => 'foo' }, f.head.specs) assert_equal({ :tag => 'foo' }, f.head.specs)
assert_equal CurlDownloadStrategy, f.stable.download_strategy assert_equal CurlDownloadStrategy, f.stable.download_strategy