From 2e2023b88b679f7b814d2258a54e757fb4243fb1 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Tue, 9 Dec 2014 08:34:15 -0500 Subject: [PATCH] Be more consistent/liberal about stanza accessors. Return the current value whenever the stanza method is called without arguments, including when the stanza has no value. Do not attempt to construct an instance with no arguments (which typically throws an exception). Incidental comment re: depends_on Refs #7880 --- lib/cask/dsl.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/cask/dsl.rb b/lib/cask/dsl.rb index bac08b2689785..0cb8bcea4fbe1 100644 --- a/lib/cask/dsl.rb +++ b/lib/cask/dsl.rb @@ -82,6 +82,7 @@ def homepage(homepage=nil) end def url(*args) + return @url if args.empty? if @url and !args.empty? raise CaskInvalidError.new(self.token, "'url' stanza may only appear once") end @@ -93,6 +94,7 @@ def url(*args) end def appcast(*args) + return @appcast if args.empty? if @appcast and !args.empty? raise CaskInvalidError.new(self.token, "'appcast' stanza may only appear once") end @@ -104,6 +106,7 @@ def appcast(*args) end def gpg(*args) + return @gpg if args.empty? if @gpg and !args.empty? raise CaskInvalidError.new(self.token, "'gpg' stanza may only appear once") end @@ -115,6 +118,7 @@ def gpg(*args) end def container(*args) + return @container if args.empty? if @container and !args.empty? # todo: remove this constraint, and instead merge multiple container stanzas raise CaskInvalidError.new(self.token, "'container' stanza may only appear once") @@ -147,6 +151,7 @@ def version(arg=nil) end def tags(*args) + return @tags if args.empty? if @tags and !args.empty? # consider removing this limitation raise CaskInvalidError.new(self.token, "'tags' stanza may only appear once") @@ -159,6 +164,7 @@ def tags(*args) end def license(arg=nil) + return @license if arg.nil? if @license and !arg.nil? raise CaskInvalidError.new(self.token, "'license' stanza may only appear once") end @@ -169,7 +175,9 @@ def license(arg=nil) end end + # depends_on uses a load method so that multiple stanzas can be merged def depends_on(*args) + return @depends_on if args.empty? @depends_on ||= Cask::DSL::DependsOn.new() begin @depends_on.load(*args) unless args.empty? @@ -184,6 +192,7 @@ def conflicts_with(*args) # todo: remove this constraint, and instead merge multiple conflicts_with stanzas raise CaskInvalidError.new(self.token, "'conflicts_with' stanza may only appear once") end + return @conflicts_with if args.empty? @conflicts_with ||= begin Cask::DSL::ConflictsWith.new(*args) unless args.empty? rescue StandardError => e