Skip to content

Commit

Permalink
Merge pull request #4849 from rolandwalker/version_symbol_latest
Browse files Browse the repository at this point in the history
DSL: allow `version :latest` (symbol not string)
  • Loading branch information
rolandwalker committed Jun 28, 2014
2 parents cc7db15 + 4052928 commit 0d01d35
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def caskroom_path
end

def destination_path
caskroom_path.join(version)
caskroom_path.join(version.to_s)
end

def installed?
Expand Down
8 changes: 6 additions & 2 deletions lib/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/cask/caveats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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
Expand Down
2 changes: 1 addition & 1 deletion lib/cask/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,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)
Expand Down

0 comments on commit 0d01d35

Please sign in to comment.