From 4052928deb556da65fe7730504434f6dddd7bb3e Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Thu, 12 Jun 2014 16:28:11 -0400 Subject: [PATCH] DSL: allow `version :latest` (symbol not string) Forward-compatibility. Intentionally not documented. When version is a symbol, it may only be `:latest`. References: #4688 --- lib/cask.rb | 2 +- lib/cask/audit.rb | 8 ++++++-- lib/cask/caveats.rb | 2 +- lib/cask/download_strategy.rb | 2 +- lib/cask/dsl.rb | 14 +++++++++++--- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/cask.rb b/lib/cask.rb index 7827badbd9809..e1ec9cc7973fc 100644 --- a/lib/cask.rb +++ b/lib/cask.rb @@ -135,7 +135,7 @@ def caskroom_path end def destination_path - caskroom_path.join(version) + caskroom_path.join(version.to_s) end def installed? diff --git a/lib/cask/audit.rb b/lib/cask/audit.rb index 6ceb580fd867d..d0ab957ffb38d 100644 --- a/lib/cask/audit.rb +++ b/lib/cask/audit.rb @@ -40,12 +40,16 @@ def _check_checksums def _check_sha256_no_check_if_latest odebug "Verifying sha256 :no_check with version 'latest'" - add_error "you should use sha256 :no_check when version is 'latest'" if cask.version == "latest" && cask.sums.is_a?(Array) + if ((cask.version == "latest" or cask.version == :latest) and cask.sums.is_a?(Array)) + add_error "you should use sha256 :no_check when version is 'latest'" + end end def _check_sha256_if_versioned odebug "Verifying a sha256 is present when versioned" - add_error "you must include a sha256 when version is not 'latest'" if cask.version != "latest" && cask.sums == :no_check + if ((cask.version != "latest" and cask.version != :latest) and cask.sums == :no_check) + add_error "you must include a sha256 when version is not 'latest'" + end end def _check_download(download) diff --git a/lib/cask/caveats.rb b/lib/cask/caveats.rb index d187f9dde20cd..46980bd4b37a0 100644 --- a/lib/cask/caveats.rb +++ b/lib/cask/caveats.rb @@ -29,7 +29,7 @@ def caskroom_path end def destination_path - caskroom_path.join(@cask.version) + caskroom_path.join(@cask.version.to_s) end # DSL. Each method should handle output, following the convention of diff --git a/lib/cask/download_strategy.rb b/lib/cask/download_strategy.rb index c08bde573bc29..b41e9af8e46a4 100644 --- a/lib/cask/download_strategy.rb +++ b/lib/cask/download_strategy.rb @@ -17,7 +17,7 @@ def initialize(cask, command=Cask::SystemCommand) cask.title, ::Resource.new(cask.title) do |r| r.url cask.url.to_s - r.version cask.version + r.version cask.version.to_s end ) end diff --git a/lib/cask/dsl.rb b/lib/cask/dsl.rb index fd182333f3e7b..ca89a1c83cade 100644 --- a/lib/cask/dsl.rb +++ b/lib/cask/dsl.rb @@ -57,11 +57,19 @@ def container_type(type=nil) @container_type ||= type end - def version(version=nil) - if @version and !version.nil? + SYMBOLIC_VERSIONS = Set.new [ + :latest, + ] + + def version(arg=nil) + if arg.nil? + @version + elsif @version raise CaskInvalidError.new(self.title, "'version' stanza may only appear once") + elsif !arg.is_a?(String) and !SYMBOLIC_VERSIONS.include?(arg) + raise CaskInvalidError.new(self.title, "invalid 'version' value: '#{arg.inspect}'") end - @version ||= version + @version ||= arg end def depends_on_formula(*args)