Extract a new superclass for VCS-based download strategies

This commit is contained in:
Jack Nagel 2013-10-09 21:41:15 -05:00
parent e27574b27b
commit 6c5a9ae0fb
2 changed files with 15 additions and 9 deletions

View File

@ -9,8 +9,6 @@ class AbstractDownloadStrategy
@name = name @name = name
@resource = resource @resource = resource
@url = resource.url @url = resource.url
specs = resource.specs
@ref_type, @ref = specs.dup.shift unless specs.empty?
end end
def expand_safe_system_args args def expand_safe_system_args args
@ -48,6 +46,14 @@ class AbstractDownloadStrategy
def cached_location; end def cached_location; end
end end
class VCSDownloadStrategy < AbstractDownloadStrategy
def initialize name, resource
super
specs = resource.specs
@ref_type, @ref = specs.dup.shift unless specs.empty?
end
end
class CurlDownloadStrategy < AbstractDownloadStrategy class CurlDownloadStrategy < AbstractDownloadStrategy
def initialize name, resource def initialize name, resource
super super
@ -302,7 +308,7 @@ class S3DownloadStrategy < CurlDownloadStrategy
end end
end end
class SubversionDownloadStrategy < AbstractDownloadStrategy class SubversionDownloadStrategy < VCSDownloadStrategy
def initialize name, resource def initialize name, resource
super super
@@svn ||= 'svn' @@svn ||= 'svn'
@ -414,7 +420,7 @@ class UnsafeSubversionDownloadStrategy < SubversionDownloadStrategy
end end
end end
class GitDownloadStrategy < AbstractDownloadStrategy class GitDownloadStrategy < VCSDownloadStrategy
def initialize name, resource def initialize name, resource
super super
@@git ||= 'git' @@git ||= 'git'
@ -562,7 +568,7 @@ class GitDownloadStrategy < AbstractDownloadStrategy
end end
end end
class CVSDownloadStrategy < AbstractDownloadStrategy class CVSDownloadStrategy < VCSDownloadStrategy
def initialize name, resource def initialize name, resource
super super
@co = Pathname.new("#{HOMEBREW_CACHE}/#{checkout_name("cvs")}") @co = Pathname.new("#{HOMEBREW_CACHE}/#{checkout_name("cvs")}")
@ -612,7 +618,7 @@ class CVSDownloadStrategy < AbstractDownloadStrategy
end end
end end
class MercurialDownloadStrategy < AbstractDownloadStrategy class MercurialDownloadStrategy < VCSDownloadStrategy
def initialize name, resource def initialize name, resource
super super
@clone = Pathname.new("#{HOMEBREW_CACHE}/#{checkout_name("hg")}") @clone = Pathname.new("#{HOMEBREW_CACHE}/#{checkout_name("hg")}")
@ -667,7 +673,7 @@ class MercurialDownloadStrategy < AbstractDownloadStrategy
end end
end end
class BazaarDownloadStrategy < AbstractDownloadStrategy class BazaarDownloadStrategy < VCSDownloadStrategy
def initialize name, resource def initialize name, resource
super super
@clone = Pathname.new("#{HOMEBREW_CACHE}/#{checkout_name("bzr")}") @clone = Pathname.new("#{HOMEBREW_CACHE}/#{checkout_name("bzr")}")
@ -715,7 +721,7 @@ class BazaarDownloadStrategy < AbstractDownloadStrategy
end end
end end
class FossilDownloadStrategy < AbstractDownloadStrategy class FossilDownloadStrategy < VCSDownloadStrategy
def initialize name, resource def initialize name, resource
super super
@clone = Pathname.new("#{HOMEBREW_CACHE}/#{checkout_name("fossil")}") @clone = Pathname.new("#{HOMEBREW_CACHE}/#{checkout_name("fossil")}")

View File

@ -40,7 +40,7 @@ end
class DownloadStrategyCheckoutNameTests < Test::Unit::TestCase class DownloadStrategyCheckoutNameTests < Test::Unit::TestCase
def setup def setup
@resource = ResourceDouble.new("http://foo.com/bar") @resource = ResourceDouble.new("http://foo.com/bar")
@strategy = AbstractDownloadStrategy @strategy = VCSDownloadStrategy
end end
def escaped(tag) def escaped(tag)