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

Add name stanza for proper name #7805

Merged
merged 1 commit into from
Dec 6, 2014
Merged
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
1 change: 1 addition & 0 deletions lib/cask/cli/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def self.template(cask_token)
sha256 ''

url 'https://'
name ''
homepage ''
license :unknown

Expand Down
8 changes: 7 additions & 1 deletion lib/cask/cli/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ def self.info(cask)
else
"Not installed"
end

# todo completely reformat the info report
<<-PURPOSE
#{cask}: #{cask.version}
#{formatted_full_name(cask) }
#{cask.homepage or 'No Homepage'}
#{installation}
#{github_info(cask) or 'No GitHub URL'}
#{artifact_info(cask) or 'No Artifact Info'}
PURPOSE
end

def self.formatted_full_name(cask)
# todo transitional: make name a required stanza, and then stop substituting cask.token here
cask.full_name.empty? ? cask.token : cask.full_name.join(', ')
end

def self.github_info(cask)
cask_token = cask.token
cask_token = cask.class.all_tokens.detect { |t| t.split("/").last == cask_token } unless cask_token =~ /\//
Expand Down
3 changes: 2 additions & 1 deletion lib/cask/cli/internal_stanza.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def self.run(*arguments)

def self.print_stanzas(stanza, format=nil, table=nil, quiet=nil, *cask_tokens)
count = 0
stanza = :sums if stanza == :sha256
stanza = :sums if stanza == :sha256
stanza = :full_name if stanza == :name
if ARTIFACTS.include?(stanza)
artifact_name = stanza
stanza = :artifacts
Expand Down
23 changes: 23 additions & 0 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def self.included(base)
base.extend(ClassMethods)
end

def full_name; self.class.full_name; end

def homepage; self.class.homepage; end

def url; self.class.url; end
Expand Down Expand Up @@ -49,6 +51,27 @@ def artifacts; self.class.artifacts; end
def caveats; self.class.caveats; end

module ClassMethods

# A quite fragile shim to allow "full_name" be exposed as simply "name"
# in the DSL. We detect the difference with the already-existing "name"
# method by arity, and use "full_name" exclusively in backend code.
def name(*args)
if args.empty?
super
else
self.full_name(args)
end
end

def full_name(_full_name=nil)
@full_name ||= []
if _full_name
# todo this idiom may be preferred to << if it behaves the same on Ruby 1.8 and 2.x
@full_name.concat(Array(*_full_name))
end
@full_name
end

def homepage(homepage=nil)
if @homepage and !homepage.nil?
raise CaskInvalidError.new(self.token, "'homepage' stanza may only appear once")
Expand Down
5 changes: 4 additions & 1 deletion lib/cask/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def dumpcask
odebug "Cask instance dumps in YAML:"
odebug "Cask instance toplevel:", self.to_yaml
[
:full_name,
:homepage,
:url,
:appcast,
Expand All @@ -99,7 +100,9 @@ def dumpcask
:container,
:gpg,
].each do |method|
odebug "Cask instance method '#{method}':", self.send(method).to_yaml
printable_method = method.to_s
printable_method = "name" if printable_method == "full_name"
odebug "Cask instance method '#{printable_method}':", self.send(method).to_yaml
end
end
end
Expand Down
1 change: 1 addition & 0 deletions test/cask/cli/create_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def self.editor_commands
sha256 ''

url 'https://'
name ''
homepage ''
license :unknown

Expand Down
5 changes: 5 additions & 0 deletions test/cask/cli/info_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Cask::CLI::Info.run('local-caffeine')
}.must_output <<-CLIOUTPUT.undent
local-caffeine: 1.2.3
local-caffeine
http://example.com/local-caffeine
Not installed
https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/local-caffeine.rb
Expand All @@ -18,12 +19,14 @@
before do
@expected_output = <<-CLIOUTPUT.undent
local-caffeine: 1.2.3
local-caffeine
http://example.com/local-caffeine
Not installed
https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/local-caffeine.rb
==> Contents
Caffeine.app (app)
local-transmission: 2.61
local-transmission
http://example.com/local-transmission
Not installed
https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/local-transmission.rb
Expand All @@ -50,6 +53,7 @@
Cask::CLI::Info.run('with-caveats')
}.must_output <<-CLIOUTPUT.undent
with-caveats: 1.2.3
with-caveats
http://example.com/local-caffeine
Not installed
https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/with-caveats.rb
Expand All @@ -74,6 +78,7 @@
Cask::CLI::Info.run('with-conditional-caveats')
}.must_output <<-CLIOUTPUT.undent
with-conditional-caveats: 1.2.3
with-conditional-caveats
http://example.com/local-caffeine
Not installed
https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/with-conditional-caveats.rb
Expand Down
39 changes: 39 additions & 0 deletions test/cask/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,45 @@
end
end

describe "name stanza" do
it "lets you set the full name via a name stanza" do
NameCask = Class.new(Cask)
NameCask.class_eval do
name 'Proper Name'
end
instance = NameCask.new
instance.full_name.must_equal [
'Proper Name',
]
end

it "Accepts an array value to the name stanza" do
ArrayNameCask = Class.new(Cask)
ArrayNameCask.class_eval do
name ['Proper Name', 'Alternate Name']
end
instance = ArrayNameCask.new
instance.full_name.must_equal [
'Proper Name',
'Alternate Name',
]
end

it "Accepts multiple name stanzas" do
MultiNameCask = Class.new(Cask)
MultiNameCask.class_eval do
name 'Proper Name'
name 'Alternate Name'
end
instance = MultiNameCask.new
# the sort is a hack to deal with Ruby 1.8 oddities
instance.full_name.sort.must_equal [
'Proper Name',
'Alternate Name',
].sort
end
end

describe "sha256 stanza" do
it "lets you set checksum via sha256" do
ChecksumCask = Class.new(Cask)
Expand Down