Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL: add dsl stanza, defining DSL specification version for a Cask #4870

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ def self.included(base)
base.extend(ClassMethods)
end

# Slightly confusing: there is a method "dsl" inside the
# namespace Cask::DSL. Lowercase "dsl" follows the Cask
# stanza "dsl", which is nothing more than a version number
# for the Cask language spec.
def dsl; self.class.dsl; end

def homepage; self.class.homepage; end

def url; self.class.url; end
Expand All @@ -25,6 +31,13 @@ def artifacts; self.class.artifacts; end
def caveats; self.class.caveats; end

module ClassMethods
def dsl(arg=nil)
if @dsl and !arg.nil?
raise CaskInvalidError.new(self.title, "'dsl' stanza may only appear once")
end
@dsl ||= arg
end

def homepage(homepage=nil)
if @homepage and !homepage.nil?
raise CaskInvalidError.new(self.title, "'homepage' stanza may only appear once")
Expand Down
1 change: 1 addition & 0 deletions lib/cask/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def dumpcask
odebug "Cask instance dumps in YAML:"
odebug "Cask instance toplevel:", self.to_yaml
[
:dsl,
:homepage,
:url,
:appcast,
Expand Down
14 changes: 14 additions & 0 deletions test/cask/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,18 @@ def caveats; <<-EOS.undent
}.must_raise(CaskInvalidError)
err.message.must_include "'version' stanza may only appear once"
end

describe "dsl stanza" do
it "allows dsl version to be defined" do
cask = Cask.load('with-dsl-stanza')
cask.dsl.to_s.must_match %r{\S}
end

it "prevents defining dsl version multiple times" do
err = lambda {
invalid_cask = Cask.load('invalid/invalid-dsl-stanza-multiple')
}.must_raise(CaskInvalidError)
err.message.must_include "'dsl' stanza may only appear once"
end
end
end
9 changes: 9 additions & 0 deletions test/support/Casks/invalid/invalid-dsl-stanza-multiple.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class InvalidDslStanzaMultiple < TestCask
dsl '1.0'
dsl '1.0'
url TestHelper.local_binary('caffeine.zip')
homepage 'http://example.com/invalid-dsl-stanza-multiple'
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853'
version '1.2.3'
link 'Caffeine.app'
end
8 changes: 8 additions & 0 deletions test/support/Casks/with-dsl-stanza.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class WithDslStanza < TestCask
dsl '1.0'
url TestHelper.local_binary('caffeine.zip')
homepage 'http://example.com/with-dsl-stanza'
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853'
version '1.2.3'
link 'Caffeine.app'
end