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

Remove constraint that Cask tokens cannot start with digits #7822

Merged
merged 4 commits 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
2 changes: 1 addition & 1 deletion Casks/ax88179.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Utils
def self.basename
"AX88179_178A_Macintosh_10.6_to_10.10_Driver_Installer_v#{Ax88179.version}"
"AX88179_178A_Macintosh_10.6_to_10.10_Driver_Installer_v#{Module.nesting.last.version}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion Casks/ax88772.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Utils
def self.basename
"AX88772C_772B_772A_760_772_Macintosh_10.5_to_10.10_Driver_Installer_v#{Ax88772.version}"
"AX88772C_772B_772A_760_772_Macintosh_10.5_to_10.10_Driver_Installer_v#{Module.nesting.last.version}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion Casks/mcs783x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Utils
def self.basename
"MCS783x_Mac_OSX_10.5_to_10.7_driver_v#{Mcs783x.version}_Binary"
"MCS783x_Mac_OSX_10.5_to_10.7_driver_v#{Module.nesting.last.version}_Binary"
end
end

Expand Down
22 changes: 0 additions & 22 deletions developer/bin/generate_cask_token
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,6 @@ end
### configurable constants
###

EXPANDED_NUMBERS = {
'0' => 'zero',
'1' => 'one',
'2' => 'two',
'3' => 'three',
'4' => 'four',
'5' => 'five',
'6' => 'six',
'7' => 'seven',
'8' => 'eight',
'9' => 'nine',
}

EXPANDED_SYMBOLS = {
'+' => 'plus',
}
Expand Down Expand Up @@ -302,14 +289,6 @@ class CaskFileName < String
self.gsub(/-([0-9])/, '\1')
end

def spell_out_leading_numbers
cask_file_name = self
EXPANDED_NUMBERS.each do |k, v|
cask_file_name.sub!(/^#{k}/, v)
end
cask_file_name
end

def spell_out_symbols
cask_file_name = self
EXPANDED_SYMBOLS.each do |k, v|
Expand Down Expand Up @@ -339,7 +318,6 @@ class CaskFileName < String
.collapse_multiple_hyphens
.delete_leading_hyphens
.delete_hyphens_before_numbers
.spell_out_leading_numbers
end
raise "Could not determine Simplified App name" unless @from_simplified_app_name.length > 0
@from_simplified_app_name.add_extension
Expand Down
4 changes: 0 additions & 4 deletions doc/cask_token_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ distribution, use [`tags :name`](CASK_LANGUAGE_REFERENCE.md#tags-stanza-details)

* Remove from the end: localization strings such as "en-US"

* Pay attention to details, for example: `"Git Hub" != "git_hub" != "GitHub"`

* If the result of that process is a generic term, such as "Macintosh Installer",
try prepending the name of the vendor or developer, followed by a hyphen.
If that doesn't work, then just create the best name you can, based on the
Expand Down Expand Up @@ -142,7 +140,6 @@ To convert the App's Simplified Name (above) to a token:
* delete any character which is not alphanumeric or hyphen
* collapse a series of multiple hyphens into one hyphen
* delete a leading or trailing hyphen
* a leading number gets spelled out into English: `1password` becomes `onepassword`

We avoid defining Cask tokens in the repository which differ only by the
placement of hyphens. Prepend the vendor name if needed to disambiguate
Expand All @@ -168,7 +165,6 @@ App Name on Disk | Simplified App Name | Cask Token | Filename
`BetterTouchTool.app` | BetterTouchTool | bettertouchtool | `bettertouchtool.rb`
`LPK25 Editor.app` | LPK25 Editor | lpk25-editor | `lpk25-editor.rb`
`Sublime Text 2.app` | Sublime Text | sublime-text | `sublime-text.rb`
`1Password.app` | 1Password | onepassword | `onepassword.rb`


# <3 THANK YOU TO ALL CONTRIBUTORS! <3
4 changes: 3 additions & 1 deletion lib/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def self.load(query)
end

def self.token
self.name.gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').downcase
# todo removeme: prepending KlassPrefix is transitional as we move away from representing Casks as classes
self.name.sub(/^KlassPrefix/,'').gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').downcase
end

# todo removeme transitional backward-compatibility
Expand Down Expand Up @@ -114,6 +115,7 @@ def caskroom_path
self.class.caskroom.join(token)
end

# todo: move to staged.rb ?
def staged_path
cask_version = version ? version : :unknown
caskroom_path.join(cask_version.to_s)
Expand Down
3 changes: 2 additions & 1 deletion lib/cask/source/path_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def cask_token
end

def cask_class_name
cask_token.split('-').map(&:capitalize).join
# todo removeme: prepending KlassPrefix is transitional as we move away from representing Casks as classes
'KlassPrefix'.concat cask_token.split('-').map(&:capitalize).join
end

def to_s
Expand Down
32 changes: 16 additions & 16 deletions test/cask_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
it "returns an instance of the Cask for the given token" do
c = Cask.load("adium")
c.must_be_kind_of(Cask)
c.must_be_instance_of(Adium)
c.must_be_instance_of(KlassPrefixAdium)
end

it "returns an instance of the Cask from a specific file location" do
# defensive constant cleanup is required because Cask
# classes may already be loaded due to audit test
begin
Object.class_eval{remove_const :Dia}
Object.class_eval{remove_const :KlassPrefixDia}
rescue
end
location = File.expand_path('./Casks/dia.rb')
c = Cask.load(location)
c.must_be_kind_of(Cask)
c.must_be_instance_of(Dia)
Object.class_eval{remove_const :Dia}
c.must_be_instance_of(KlassPrefixDia)
Object.class_eval{remove_const :KlassPrefixDia}
end

it "returns an instance of the Cask from a url" do
begin
Object.class_eval{remove_const :Dia}
Object.class_eval{remove_const :KlassPrefixDia}
rescue
end
url = "file://" + File.expand_path('./Casks/dia.rb')
c = shutup do
Cask.load(url)
end
c.must_be_kind_of(Cask)
c.must_be_instance_of(Dia)
Object.class_eval{remove_const :Dia}
c.must_be_instance_of(KlassPrefixDia)
Object.class_eval{remove_const :KlassPrefixDia}
end

it "raises an error when failing to download a Cask from a url" do
Expand All @@ -47,18 +47,18 @@

it "returns an instance of the Cask from a relative file location" do
begin
Object.class_eval{remove_const :Bbedit}
Object.class_eval{remove_const :KlassPrefixBbedit}
rescue
end
c = Cask.load("./Casks/bbedit.rb")
c.must_be_kind_of(Cask)
c.must_be_instance_of(Bbedit)
Object.class_eval{remove_const :Bbedit}
c.must_be_instance_of(KlassPrefixBbedit)
Object.class_eval{remove_const :KlassPrefixBbedit}
end

it "uses exact match when loading by token" do
Cask.load('test-opera').must_be_instance_of(TestOpera)
Cask.load('test-opera-mail').must_be_instance_of(TestOperaMail)
Cask.load('test-opera').must_be_instance_of(KlassPrefixTestOpera)
Cask.load('test-opera-mail').must_be_instance_of(KlassPrefixTestOperaMail)
end

it "raises an error when attempting to load a Cask that doesn't exist" do
Expand All @@ -78,13 +78,13 @@

describe "token" do
it "converts a class constant to a token-style dashed string" do
PascalCasedConstant = Class.new(Cask)
PascalCasedConstant.token.must_equal 'pascal-cased-constant'
KlassPrefixPascalCasedConstant = Class.new(Cask)
KlassPrefixPascalCasedConstant.token.must_equal 'pascal-cased-constant'
end

it "properly dasherizes constants with single letters in the middle" do
GamesXChange = Class.new(Cask)
GamesXChange.token.must_equal 'games-x-change'
KlassPrefixGamesXChange = Class.new(Cask)
KlassPrefixGamesXChange.token.must_equal 'games-x-change'
end
end

Expand Down