Skip to content

Commit

Permalink
remove constraint that tokens can't start w/ digit
Browse files Browse the repository at this point in the history
Class names are now completely hidden from the user.  This
commit works by adding a prefix to all Cask class names, which
is considered to be an ugly transitional hack on the way to
representing individual Casks as instances.
  • Loading branch information
rolandwalker committed Dec 5, 2014
1 parent aa58f55 commit cb5a40f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 44 deletions.
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

0 comments on commit cb5a40f

Please sign in to comment.