Module: Cask::TokenGenerator Private
- Extended by:
- SystemCommand::Mixin
- Defined in:
- cask/token_generator.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Generates a cask token from an application name or bundle path, following the token conventions described in the Cask Cookbook.
Constant Summary collapse
- EXPANDED_SYMBOLS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let({ "+" => "plus", "@" => "at", }.freeze, T::Hash[String, String])
- PRESERVE_TRAILING_PATS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
Trailing patterns on app names that could be mistaken for version numbers etc. but should be preserved.
T.let([ /id3/i, /mp3/i, /3[\s-]*d/i, /diff3/i, /\A[^\d]+\+\Z/i, ].freeze, T::Array[Regexp])
- PRESERVE_TRAILING_PAT =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
/(?:#{Regexp.union(PRESERVE_TRAILING_PATS)})\Z/i- REMOVE_TRAILING_PATS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
These patterns are applied repeatedly to the end of the app name until none matches, after word breaks have been inserted at CamelCase and snake_case transitions.
T.let([ # spaces /\s+/i, # generic terms /\bapp/i, /\b(?:quick[\s-]*)?launcher/i, # "mac", "for mac", "for OS X", "macOS", "for macOS". /\b(?:for)?[\s-]*mac(?:intosh|OS)?/i, /\b(?:for)?[\s-]*os[\s-]*x/i, # hardware designations such as "for x86", "32-bit", "ppc" /(?:\bfor\s*)?x.?86/i, /(?:\bfor\s*)?\bppc/i, /(?:\bfor\s*)?\barm(?:64|v\d+)?/i, /(?:\bfor\s*)?\d+.?bits?/i, # frameworks /\b(?:for)?[\s-]*(?:oracle|apple|sun)*[\s-]*(?:jvm|java|jre)/i, /\bgtk/i, /\bqt/i, /\bwx/i, /\bcocoa/i, # localizations /en\s*-\s*us/i, # trailing punctuation /[^a-z0-9]+/i, # release qualifiers, which are words rather than bare version numbers /\b(?:version|alpha|beta|gamma|release|release.?candidate)(?:[\s.\d-]*\d[\s.\d-]*)?/i, ].freeze, T::Array[Regexp])
- REMOVE_TRAILING_PAT =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
/(?<=.)(?:#{Regexp.union(REMOVE_TRAILING_PATS)})\Z/i
Class Method Summary collapse
- .generate(app) ⇒ String private
- .simplified_app_name(app) ⇒ String private
- .token_for(app_name) ⇒ String private
- .warnings(token) ⇒ Array<String> private
Methods included from SystemCommand::Mixin
system_command, system_command!
Class Method Details
.generate(app) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
68 69 70 |
# File 'cask/token_generator.rb', line 68 def self.generate(app) token_for(simplified_app_name(app)) end |
.simplified_app_name(app) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
73 74 75 76 77 78 |
# File 'cask/token_generator.rb', line 73 def self.simplified_app_name(app) name = english_app_name(app.dup.force_encoding(Encoding::UTF_8)) name = Pathname(name).basename.to_s if Pathname(name).exist? name = decompose_to_ascii(name).sub(/\.app\Z/i, "") remove_trailing_strings(name) end |
.token_for(app_name) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'cask/token_generator.rb', line 81 def self.token_for(app_name) token = app_name.downcase EXPANDED_SYMBOLS.each do |symbol, word| token = token.gsub(symbol, " #{word} ") end token = token.sub(/ +\Z/, "") .gsub(/ +/, "-") .gsub(/[^a-z0-9-]+/, "") .gsub(/--+/, "-") .gsub(/\A-+|-+\z/, "") raise UsageError, "Could not determine a token from '#{app_name}'." if token.empty? token end |
.warnings(token) ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
97 98 99 100 101 102 103 104 |
# File 'cask/token_generator.rb', line 97 def self.warnings(token) warnings = [] if token.sub(/@.*\z/, "").match?(/\d/) warnings << "'#{token}' contains digits. If they are a version number, " \ "remove them from the token and file name." end warnings end |