diff options
| author | Markus Reiter | 2016-09-24 13:52:43 +0200 |
|---|---|---|
| committer | Markus Reiter | 2016-09-24 16:00:58 +0200 |
| commit | b86c8efb79b3ed835d552c4d7416640ef10caf21 (patch) | |
| tree | 7e1edc8a8f339e4d2781f43576d40c9c79aebcdc /Library/Homebrew/cask/lib/hbc/dsl | |
| parent | 687f0fcf721c8e36f32570ed72d0988a6eaf986f (diff) | |
| download | brew-b86c8efb79b3ed835d552c4d7416640ef10caf21.tar.bz2 | |
Cask: Use nested classes and modules.
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/dsl')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/appcast.rb | 28 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/base.rb | 48 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/caveats.rb | 158 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb | 52 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/container.rb | 44 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/depends_on.rb | 214 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/gpg.rb | 72 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/installer.rb | 48 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/license.rb | 112 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/postflight.rb | 12 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/preflight.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb | 88 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/uninstall_postflight.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/uninstall_preflight.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/version.rb | 184 |
15 files changed, 571 insertions, 511 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb index b02616cfe..2f1245d3d 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb @@ -1,17 +1,21 @@ -class Hbc::DSL::Appcast - attr_reader :parameters, :checkpoint +module Hbc + class DSL + class Appcast + attr_reader :parameters, :checkpoint - def initialize(uri, parameters = {}) - @parameters = parameters - @uri = Hbc::UnderscoreSupportingURI.parse(uri) - @checkpoint = @parameters[:checkpoint] - end + def initialize(uri, parameters = {}) + @parameters = parameters + @uri = UnderscoreSupportingURI.parse(uri) + @checkpoint = @parameters[:checkpoint] + end - def to_yaml - [@uri, @parameters].to_yaml - end + def to_yaml + [@uri, @parameters].to_yaml + end - def to_s - @uri.to_s + def to_s + @uri.to_s + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/base.rb b/Library/Homebrew/cask/lib/hbc/dsl/base.rb index f47f3aab7..ccf93dae9 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/base.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/base.rb @@ -1,29 +1,33 @@ -class Hbc::DSL::Base - extend Forwardable +module Hbc + class DSL + class Base + extend Forwardable - def initialize(cask, command = Hbc::SystemCommand) - @cask = cask - @command = command - end + def initialize(cask, command = SystemCommand) + @cask = cask + @command = command + end - def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir + def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir - def system_command(executable, options = {}) - @command.run!(executable, options) - end + def system_command(executable, options = {}) + @command.run!(executable, options) + end - def method_missing(method, *) - if method - underscored_class = self.class.name.gsub(%r{([[:lower:]])([[:upper:]][[:lower:]])}, '\1_\2').downcase - section = underscored_class.downcase.split("::").last - Hbc::Utils.method_missing_message(method, @cask.to_s, section) - nil - else - super - end - end + def method_missing(method, *) + if method + underscored_class = self.class.name.gsub(%r{([[:lower:]])([[:upper:]][[:lower:]])}, '\1_\2').downcase + section = underscored_class.downcase.split("::").last + Utils.method_missing_message(method, @cask.to_s, section) + nil + else + super + end + end - def respond_to_missing?(*) - true + def respond_to_missing?(*) + true + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb index d872f49cb..5efd7d562 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb @@ -5,108 +5,112 @@ # ( The return value of the last method in the block is also sent # to the output by the caller, but that feature is only for the # convenience of Cask authors. ) -class Hbc::DSL::Caveats < Hbc::DSL::Base - def path_environment_variable(path) - puts <<-EOS.undent - To use #{@cask}, you may need to add the #{path} directory - to your PATH environment variable, eg (for bash shell): +module Hbc + class DSL + class Caveats < Base + def path_environment_variable(path) + puts <<-EOS.undent + To use #{@cask}, you may need to add the #{path} directory + to your PATH environment variable, eg (for bash shell): - export PATH=#{path}:"$PATH" + export PATH=#{path}:"$PATH" - EOS - end + EOS + end - def zsh_path_helper(path) - puts <<-EOS.undent - To use #{@cask}, zsh users may need to add the following line to their - ~/.zprofile. (Among other effects, #{path} will be added to the - PATH environment variable): + def zsh_path_helper(path) + puts <<-EOS.undent + To use #{@cask}, zsh users may need to add the following line to their + ~/.zprofile. (Among other effects, #{path} will be added to the + PATH environment variable): - eval `/usr/libexec/path_helper -s` + eval `/usr/libexec/path_helper -s` - EOS - end + EOS + end - def files_in_usr_local - localpath = "/usr/local" - return unless Hbc.homebrew_prefix.to_s.downcase.start_with?(localpath) - puts <<-EOS.undent - Cask #{@cask} installs files under "#{localpath}". The presence of such - files can cause warnings when running "brew doctor", which is considered - to be a bug in Homebrew-Cask. + def files_in_usr_local + localpath = "/usr/local" + return unless Hbc.homebrew_prefix.to_s.downcase.start_with?(localpath) + puts <<-EOS.undent + Cask #{@cask} installs files under "#{localpath}". The presence of such + files can cause warnings when running "brew doctor", which is considered + to be a bug in Homebrew-Cask. - EOS - end + EOS + end - def depends_on_java(java_version = "any") - if java_version == "any" - puts <<-EOS.undent - #{@cask} requires Java. You can install the latest version with + def depends_on_java(java_version = "any") + if java_version == "any" + puts <<-EOS.undent + #{@cask} requires Java. You can install the latest version with - brew cask install java + brew cask install java - EOS - elsif java_version.include?("8") || java_version.include?("+") - puts <<-EOS.undent - #{@cask} requires Java #{java_version}. You can install the latest version with + EOS + elsif java_version.include?("8") || java_version.include?("+") + puts <<-EOS.undent + #{@cask} requires Java #{java_version}. You can install the latest version with - brew cask install java + brew cask install java - EOS - else - puts <<-EOS.undent - #{@cask} requires Java #{java_version}. You can install it with + EOS + else + puts <<-EOS.undent + #{@cask} requires Java #{java_version}. You can install it with - brew cask install caskroom/versions/java#{java_version} + brew cask install caskroom/versions/java#{java_version} - EOS - end - end + EOS + end + end - def logout - puts <<-EOS.undent - You must log out and log back in for the installation of #{@cask} - to take effect. + def logout + puts <<-EOS.undent + You must log out and log back in for the installation of #{@cask} + to take effect. - EOS - end + EOS + end - def reboot - puts <<-EOS.undent - You must reboot for the installation of #{@cask} to take effect. + def reboot + puts <<-EOS.undent + You must reboot for the installation of #{@cask} to take effect. - EOS - end + EOS + end - def discontinued - puts <<-EOS.undent - #{@cask} has been officially discontinued upstream. - It may stop working correctly (or at all) in recent versions of macOS. + def discontinued + puts <<-EOS.undent + #{@cask} has been officially discontinued upstream. + It may stop working correctly (or at all) in recent versions of macOS. - EOS - end + EOS + end - def free_license(web_page) - puts <<-EOS.undent - The vendor offers a free license for #{@cask} at - #{web_page} + def free_license(web_page) + puts <<-EOS.undent + The vendor offers a free license for #{@cask} at + #{web_page} - EOS - end + EOS + end - def malware(radar_number) - puts <<-EOS.undent - #{@cask} has been reported to bundle malware. Like with any app, use at your own risk. + def malware(radar_number) + puts <<-EOS.undent + #{@cask} has been reported to bundle malware. Like with any app, use at your own risk. - A report has been made to Apple about this app. Their certificate will hopefully be revoked. - See the public report at - https://openradar.appspot.com/#{radar_number} + A report has been made to Apple about this app. Their certificate will hopefully be revoked. + See the public report at + https://openradar.appspot.com/#{radar_number} - If this report is accurate, please duplicate it at - https://bugreport.apple.com/ - If this report is a mistake, please let us know by opening an issue at - https://github.com/caskroom/homebrew-cask/issues/new + If this report is accurate, please duplicate it at + https://bugreport.apple.com/ + If this report is a mistake, please let us know by opening an issue at + https://github.com/caskroom/homebrew-cask/issues/new - EOS + EOS + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb b/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb index b2de2cd45..e121e5373 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb @@ -1,30 +1,34 @@ -class Hbc::DSL::ConflictsWith - VALID_KEYS = Set.new [ - :formula, - :cask, - :macos, - :arch, - :x11, - :java, - ] +module Hbc + class DSL + class ConflictsWith + VALID_KEYS = Set.new [ + :formula, + :cask, + :macos, + :arch, + :x11, + :java, + ] - attr_accessor(*VALID_KEYS) - attr_accessor :pairs + attr_accessor(*VALID_KEYS) + attr_accessor :pairs - def initialize(pairs = {}) - @pairs = pairs - pairs.each do |key, value| - raise "invalid conflicts_with key: '#{key.inspect}'" unless VALID_KEYS.include?(key) - writer_method = "#{key}=".to_sym - send(writer_method, value) - end - end + def initialize(pairs = {}) + @pairs = pairs + pairs.each do |key, value| + raise "invalid conflicts_with key: '#{key.inspect}'" unless VALID_KEYS.include?(key) + writer_method = "#{key}=".to_sym + send(writer_method, value) + end + end - def to_yaml - @pairs.to_yaml - end + def to_yaml + @pairs.to_yaml + end - def to_s - @pairs.inspect + def to_s + @pairs.inspect + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/container.rb b/Library/Homebrew/cask/lib/hbc/dsl/container.rb index 39f156668..56db31d97 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/container.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/container.rb @@ -1,26 +1,30 @@ -class Hbc::DSL::Container - VALID_KEYS = Set.new [ - :type, - :nested, - ] +module Hbc + class DSL + class Container + VALID_KEYS = Set.new [ + :type, + :nested, + ] - attr_accessor(*VALID_KEYS) - attr_accessor :pairs + attr_accessor(*VALID_KEYS) + attr_accessor :pairs - def initialize(pairs = {}) - @pairs = pairs - pairs.each do |key, value| - raise "invalid container key: '#{key.inspect}'" unless VALID_KEYS.include?(key) - writer_method = "#{key}=".to_sym - send(writer_method, value) - end - end + def initialize(pairs = {}) + @pairs = pairs + pairs.each do |key, value| + raise "invalid container key: '#{key.inspect}'" unless VALID_KEYS.include?(key) + writer_method = "#{key}=".to_sym + send(writer_method, value) + end + end - def to_yaml - @pairs.to_yaml - end + def to_yaml + @pairs.to_yaml + end - def to_s - @pairs.inspect + def to_s + @pairs.inspect + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/depends_on.rb b/Library/Homebrew/cask/lib/hbc/dsl/depends_on.rb index a7dba3643..0e80938b7 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/depends_on.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/depends_on.rb @@ -1,124 +1,128 @@ require "rubygems" -class Hbc::DSL::DependsOn - VALID_KEYS = Set.new [ - :formula, - :cask, - :macos, - :arch, - :x11, - :java, - ].freeze +module Hbc + class DSL + class DependsOn + VALID_KEYS = Set.new [ + :formula, + :cask, + :macos, + :arch, + :x11, + :java, + ].freeze - VALID_ARCHES = { - intel: { type: :intel, bits: [32, 64] }, - ppc: { type: :ppc, bits: [32, 64] }, - # specific - i386: { type: :intel, bits: 32 }, - x86_64: { type: :intel, bits: 64 }, - ppc_7400: { type: :ppc, bits: 32 }, - ppc_64: { type: :ppc, bits: 64 }, - }.freeze + VALID_ARCHES = { + intel: { type: :intel, bits: [32, 64] }, + ppc: { type: :ppc, bits: [32, 64] }, + # specific + i386: { type: :intel, bits: 32 }, + x86_64: { type: :intel, bits: 64 }, + ppc_7400: { type: :ppc, bits: 32 }, + ppc_64: { type: :ppc, bits: 64 }, + }.freeze - # Intentionally undocumented: catch variant spellings. - ARCH_SYNONYMS = { - x86_32: :i386, - x8632: :i386, - x8664: :x86_64, - intel_32: :i386, - intel32: :i386, - intel_64: :x86_64, - intel64: :x86_64, - amd_64: :x86_64, - amd64: :x86_64, - ppc7400: :ppc_7400, - ppc_32: :ppc_7400, - ppc32: :ppc_7400, - ppc64: :ppc_64, - }.freeze + # Intentionally undocumented: catch variant spellings. + ARCH_SYNONYMS = { + x86_32: :i386, + x8632: :i386, + x8664: :x86_64, + intel_32: :i386, + intel32: :i386, + intel_64: :x86_64, + intel64: :x86_64, + amd_64: :x86_64, + amd64: :x86_64, + ppc7400: :ppc_7400, + ppc_32: :ppc_7400, + ppc32: :ppc_7400, + ppc64: :ppc_64, + }.freeze - attr_accessor :java - attr_accessor :pairs - attr_reader :arch, :cask, :formula, :macos, :x11 + attr_accessor :java + attr_accessor :pairs + attr_reader :arch, :cask, :formula, :macos, :x11 - def initialize - @pairs ||= {} - end + def initialize + @pairs ||= {} + end - def load(pairs = {}) - pairs.each do |key, value| - raise "invalid depends_on key: '#{key.inspect}'" unless VALID_KEYS.include?(key) - writer_method = "#{key}=".to_sym - @pairs[key] = send(writer_method, value) - end - end + def load(pairs = {}) + pairs.each do |key, value| + raise "invalid depends_on key: '#{key.inspect}'" unless VALID_KEYS.include?(key) + writer_method = "#{key}=".to_sym + @pairs[key] = send(writer_method, value) + end + end - def self.coerce_os_release(arg) - @macos_symbols ||= MacOS::Version::SYMBOLS - @inverted_macos_symbols ||= @macos_symbols.invert + def self.coerce_os_release(arg) + @macos_symbols ||= MacOS::Version::SYMBOLS + @inverted_macos_symbols ||= @macos_symbols.invert - begin - if arg.is_a?(Symbol) - Gem::Version.new(@macos_symbols.fetch(arg)) - elsif arg =~ %r{^\s*:?([a-z]\S+)\s*$}i - Gem::Version.new(@macos_symbols.fetch(Regexp.last_match[1].downcase.to_sym)) - elsif @inverted_macos_symbols.key?(arg) - Gem::Version.new(arg) - else - raise + begin + if arg.is_a?(Symbol) + Gem::Version.new(@macos_symbols.fetch(arg)) + elsif arg =~ %r{^\s*:?([a-z]\S+)\s*$}i + Gem::Version.new(@macos_symbols.fetch(Regexp.last_match[1].downcase.to_sym)) + elsif @inverted_macos_symbols.key?(arg) + Gem::Version.new(arg) + else + raise + end + rescue StandardError + raise "invalid 'depends_on macos' value: #{arg.inspect}" + end end - rescue StandardError - raise "invalid 'depends_on macos' value: #{arg.inspect}" - end - end - def formula=(*arg) - @formula ||= [] - @formula.concat(Array(*arg)) - end + def formula=(*arg) + @formula ||= [] + @formula.concat(Array(*arg)) + end - def cask=(*arg) - @cask ||= [] - @cask.concat(Array(*arg)) - end + def cask=(*arg) + @cask ||= [] + @cask.concat(Array(*arg)) + end - def macos=(*arg) - @macos ||= [] - macos = if arg.count == 1 && arg.first =~ %r{^\s*(<|>|[=<>]=)\s*(\S+)\s*$} - raise "'depends_on macos' comparison expressions cannot be combined" unless @macos.empty? - operator = Regexp.last_match[1].to_sym - release = self.class.coerce_os_release(Regexp.last_match[2]) - [[operator, release]] - else - raise "'depends_on macos' comparison expressions cannot be combined" if @macos.first.is_a?(Symbol) - Array(*arg).map { |elt| - self.class.coerce_os_release(elt) - }.sort - end - @macos.concat(macos) - end + def macos=(*arg) + @macos ||= [] + macos = if arg.count == 1 && arg.first =~ %r{^\s*(<|>|[=<>]=)\s*(\S+)\s*$} + raise "'depends_on macos' comparison expressions cannot be combined" unless @macos.empty? + operator = Regexp.last_match[1].to_sym + release = self.class.coerce_os_release(Regexp.last_match[2]) + [[operator, release]] + else + raise "'depends_on macos' comparison expressions cannot be combined" if @macos.first.is_a?(Symbol) + Array(*arg).map { |elt| + self.class.coerce_os_release(elt) + }.sort + end + @macos.concat(macos) + end - def arch=(*arg) - @arch ||= [] - arches = Array(*arg).map { |elt| - elt = elt.to_s.downcase.sub(%r{^:}, "").tr("-", "_").to_sym - ARCH_SYNONYMS.key?(elt) ? ARCH_SYNONYMS[elt] : elt - } - invalid_arches = arches - VALID_ARCHES.keys - raise "invalid 'depends_on arch' values: #{invalid_arches.inspect}" unless invalid_arches.empty? - @arch.concat(arches.map { |arch| VALID_ARCHES[arch] }) - end + def arch=(*arg) + @arch ||= [] + arches = Array(*arg).map { |elt| + elt = elt.to_s.downcase.sub(%r{^:}, "").tr("-", "_").to_sym + ARCH_SYNONYMS.key?(elt) ? ARCH_SYNONYMS[elt] : elt + } + invalid_arches = arches - VALID_ARCHES.keys + raise "invalid 'depends_on arch' values: #{invalid_arches.inspect}" unless invalid_arches.empty? + @arch.concat(arches.map { |arch| VALID_ARCHES[arch] }) + end - def x11=(arg) - raise "invalid 'depends_on x11' value: #{arg.inspect}" unless [true, false].include?(arg) - @x11 = arg - end + def x11=(arg) + raise "invalid 'depends_on x11' value: #{arg.inspect}" unless [true, false].include?(arg) + @x11 = arg + end - def to_yaml - @pairs.to_yaml - end + def to_yaml + @pairs.to_yaml + end - def to_s - @pairs.inspect + def to_s + @pairs.inspect + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb b/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb index 9496a8c05..572ede227 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb @@ -1,43 +1,47 @@ -class Hbc::DSL::Gpg - KEY_PARAMETERS = Set.new [ - :key_id, - :key_url, - ] +module Hbc + class DSL + class Gpg + KEY_PARAMETERS = Set.new [ + :key_id, + :key_url, + ] - VALID_PARAMETERS = Set.new [] - VALID_PARAMETERS.merge KEY_PARAMETERS + VALID_PARAMETERS = Set.new [] + VALID_PARAMETERS.merge KEY_PARAMETERS - attr_accessor(*VALID_PARAMETERS) - attr_accessor :signature + attr_accessor(*VALID_PARAMETERS) + attr_accessor :signature - def initialize(signature, parameters = {}) - @parameters = parameters - @signature = Hbc::UnderscoreSupportingURI.parse(signature) - parameters.each do |hkey, hvalue| - raise "invalid 'gpg' parameter: '#{hkey.inspect}'" unless VALID_PARAMETERS.include?(hkey) - writer_method = "#{hkey}=".to_sym - hvalue = Hbc::UnderscoreSupportingURI.parse(hvalue) if hkey == :key_url - valid_id?(hvalue) if hkey == :key_id - send(writer_method, hvalue) - end - return if KEY_PARAMETERS.intersection(parameters.keys).length == 1 - raise "'gpg' stanza must include exactly one of: '#{KEY_PARAMETERS.to_a}'" - end + def initialize(signature, parameters = {}) + @parameters = parameters + @signature = UnderscoreSupportingURI.parse(signature) + parameters.each do |hkey, hvalue| + raise "invalid 'gpg' parameter: '#{hkey.inspect}'" unless VALID_PARAMETERS.include?(hkey) + writer_method = "#{hkey}=".to_sym + hvalue = UnderscoreSupportingURI.parse(hvalue) if hkey == :key_url + valid_id?(hvalue) if hkey == :key_id + send(writer_method, hvalue) + end + return if KEY_PARAMETERS.intersection(parameters.keys).length == 1 + raise "'gpg' stanza must include exactly one of: '#{KEY_PARAMETERS.to_a}'" + end - def valid_id?(id) - legal_lengths = Set.new [8, 16, 40] - is_valid = id.is_a?(String) && legal_lengths.include?(id.length) && id[%r{^[0-9a-f]+$}i] - raise "invalid ':key_id' value: '#{id.inspect}'" unless is_valid + def valid_id?(id) + legal_lengths = Set.new [8, 16, 40] + is_valid = id.is_a?(String) && legal_lengths.include?(id.length) && id[%r{^[0-9a-f]+$}i] + raise "invalid ':key_id' value: '#{id.inspect}'" unless is_valid - is_valid - end + is_valid + end - def to_yaml - # bug, :key_url value is not represented as an instance of Hbc::UnderscoreSupportingURI - [@signature, @parameters].to_yaml - end + def to_yaml + # bug, :key_url value is not represented as an instance of Hbc::UnderscoreSupportingURI + [@signature, @parameters].to_yaml + end - def to_s - @signature.to_s + def to_s + @signature.to_s + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/installer.rb b/Library/Homebrew/cask/lib/hbc/dsl/installer.rb index 74b4b3a91..92561c703 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/installer.rb @@ -1,28 +1,32 @@ -class Hbc::DSL::Installer - VALID_KEYS = Set.new [ - :manual, - :script, - ] +module Hbc + class DSL + class Installer + VALID_KEYS = Set.new [ + :manual, + :script, + ] - attr_accessor(*VALID_KEYS) + attr_accessor(*VALID_KEYS) - def initialize(*parameters) - raise Hbc::CaskInvalidError.new(token, "'installer' stanza requires an argument") if parameters.empty? - parameters = {}.merge(*parameters) - if parameters.key?(:script) && !parameters[:script].respond_to?(:key?) - if parameters.key?(:executable) - raise Hbc::CaskInvalidError.new(token, "'installer' stanza gave arguments for both :script and :executable") + def initialize(*parameters) + raise CaskInvalidError.new(token, "'installer' stanza requires an argument") if parameters.empty? + parameters = {}.merge(*parameters) + if parameters.key?(:script) && !parameters[:script].respond_to?(:key?) + if parameters.key?(:executable) + raise CaskInvalidError.new(token, "'installer' stanza gave arguments for both :script and :executable") + end + parameters[:executable] = parameters[:script] + parameters.delete(:script) + parameters = { script: parameters } + end + unless parameters.keys.length == 1 + raise "invalid 'installer' stanza: only one of #{VALID_KEYS.inspect} is permitted" + end + key = parameters.keys.first + raise "invalid 'installer' stanza key: '#{key.inspect}'" unless VALID_KEYS.include?(key) + writer_method = "#{key}=".to_sym + send(writer_method, parameters[key]) end - parameters[:executable] = parameters[:script] - parameters.delete(:script) - parameters = { script: parameters } end - unless parameters.keys.length == 1 - raise "invalid 'installer' stanza: only one of #{VALID_KEYS.inspect} is permitted" - end - key = parameters.keys.first - raise "invalid 'installer' stanza key: '#{key.inspect}'" unless VALID_KEYS.include?(key) - writer_method = "#{key}=".to_sym - send(writer_method, parameters[key]) end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/license.rb b/Library/Homebrew/cask/lib/hbc/dsl/license.rb index 5f607c268..affbc08f5 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/license.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/license.rb @@ -1,66 +1,70 @@ -class Hbc::DSL::License - # a generic category can always be given as a license, so - # category names should be given as both key and value - VALID_LICENSES = { - # license category - unknown: :unknown, +module Hbc + class DSL + class License + # a generic category can always be given as a license, so + # category names should be given as both key and value + VALID_LICENSES = { + # license category + unknown: :unknown, - other: :other, + other: :other, - closed: :closed, - commercial: :closed, - gratis: :closed, - freemium: :closed, + closed: :closed, + commercial: :closed, + gratis: :closed, + freemium: :closed, - oss: :oss, - affero: :oss, - apache: :oss, - arphic: :oss, - artistic: :oss, - bsd: :oss, - cc: :oss, - eclipse: :oss, - gpl: :oss, - isc: :oss, - lppl: :oss, - ncsa: :oss, - mit: :oss, - mpl: :oss, - ofl: :oss, - public_domain: :oss, - ubuntu_font: :oss, - x11: :oss, - }.freeze + oss: :oss, + affero: :oss, + apache: :oss, + arphic: :oss, + artistic: :oss, + bsd: :oss, + cc: :oss, + eclipse: :oss, + gpl: :oss, + isc: :oss, + lppl: :oss, + ncsa: :oss, + mit: :oss, + mpl: :oss, + ofl: :oss, + public_domain: :oss, + ubuntu_font: :oss, + x11: :oss, + }.freeze - DEFAULT_LICENSE = :unknown - DEFAULT_CATEGORY = VALID_LICENSES[DEFAULT_LICENSE] + DEFAULT_LICENSE = :unknown + DEFAULT_CATEGORY = VALID_LICENSES[DEFAULT_LICENSE] - attr_reader :value + attr_reader :value - def self.check_constants - categories = Set.new(VALID_LICENSES.values) - categories.each do |cat| - next if VALID_LICENSES.key?(cat) - raise "license category is not a value: '#{@cat.inspect}'" - end - end + def self.check_constants + categories = Set.new(VALID_LICENSES.values) + categories.each do |cat| + next if VALID_LICENSES.key?(cat) + raise "license category is not a value: '#{@cat.inspect}'" + end + end - def self.category(license) - VALID_LICENSES.fetch(license, DEFAULT_CATEGORY) - end + def self.category(license) + VALID_LICENSES.fetch(license, DEFAULT_CATEGORY) + end - def initialize(arg) - @value = arg - @value = DEFAULT_LICENSE if @value.nil? - return if VALID_LICENSES.key?(@value) - raise "invalid license value: '#{@value.inspect}'" - end + def initialize(arg) + @value = arg + @value = DEFAULT_LICENSE if @value.nil? + return if VALID_LICENSES.key?(@value) + raise "invalid license value: '#{@value.inspect}'" + end - def category - self.class.category(@value) - end + def category + self.class.category(@value) + end - def to_s - @value.inspect + def to_s + @value.inspect + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/postflight.rb b/Library/Homebrew/cask/lib/hbc/dsl/postflight.rb index 321c7e81a..1026f6de6 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/postflight.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/postflight.rb @@ -1,9 +1,13 @@ require "hbc/staged" -class Hbc::DSL::Postflight < Hbc::DSL::Base - include Hbc::Staged +module Hbc + class DSL + class Postflight < Base + include Staged - def suppress_move_to_applications(options = {}) - # TODO: Remove from all casks because it is no longer needed + def suppress_move_to_applications(options = {}) + # TODO: Remove from all casks because it is no longer needed + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/preflight.rb b/Library/Homebrew/cask/lib/hbc/dsl/preflight.rb index a0d53c69c..55a778706 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/preflight.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/preflight.rb @@ -1,3 +1,7 @@ -class Hbc::DSL::Preflight < Hbc::DSL::Base - include Hbc::Staged +module Hbc + class DSL + class Preflight < Base + include Staged + end + end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb b/Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb index 218178faa..b1a850c5a 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb @@ -1,45 +1,49 @@ -class Hbc::DSL::StanzaProxy - attr_reader :type - - def self.once(type) - resolved = nil - new(type) { resolved ||= yield } - end - - def initialize(type, &resolver) - @type = type - @resolver = resolver - end - - def proxy? - true - end - - def to_s - @resolver.call.to_s - end - - # Serialization for dumpcask - def encode_with(coder) - coder["type"] = type - coder["resolved"] = @resolver.call - end - - def method_missing(method, *args) - if method != :to_ary - @resolver.call.send(method, *args) - else - super +module Hbc + class DSL + class StanzaProxy + attr_reader :type + + def self.once(type) + resolved = nil + new(type) { resolved ||= yield } + end + + def initialize(type, &resolver) + @type = type + @resolver = resolver + end + + def proxy? + true + end + + def to_s + @resolver.call.to_s + end + + # Serialization for dumpcask + def encode_with(coder) + coder["type"] = type + coder["resolved"] = @resolver.call + end + + def method_missing(method, *args) + if method != :to_ary + @resolver.call.send(method, *args) + else + super + end + end + + def respond_to?(method, include_private = false) + return true if %i{encode_with proxy? to_s type}.include?(method) + return false if method == :to_ary + @resolver.call.respond_to?(method, include_private) + end + + def respond_to_missing?(*) + true + end end end - - def respond_to?(method, include_private = false) - return true if %i{encode_with proxy? to_s type}.include?(method) - return false if method == :to_ary - @resolver.call.respond_to?(method, include_private) - end - - def respond_to_missing?(*) - true - end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/uninstall_postflight.rb b/Library/Homebrew/cask/lib/hbc/dsl/uninstall_postflight.rb index bd8777ca7..f481cc357 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/uninstall_postflight.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/uninstall_postflight.rb @@ -1,2 +1,6 @@ -class Hbc::DSL::UninstallPostflight < Hbc::DSL::Base +module Hbc + class DSL + class UninstallPostflight < Base + end + end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/uninstall_preflight.rb b/Library/Homebrew/cask/lib/hbc/dsl/uninstall_preflight.rb index 994151c25..36cdec12f 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/uninstall_preflight.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/uninstall_preflight.rb @@ -1,5 +1,9 @@ require "hbc/staged" -class Hbc::DSL::UninstallPreflight < Hbc::DSL::Base - include Hbc::Staged +module Hbc + class DSL + class UninstallPreflight < Base + include Staged + end + end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/version.rb b/Library/Homebrew/cask/lib/hbc/dsl/version.rb index e01e67ea2..d4697460a 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/version.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/version.rb @@ -1,111 +1,115 @@ -class Hbc::DSL::Version < ::String - DIVIDERS = { - "." => :dots, - "-" => :hyphens, - "_" => :underscores, - "/" => :slashes, - }.freeze - - DIVIDER_REGEX = %r{(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})} - - MAJOR_MINOR_PATCH_REGEX = %r{^(\d+)(?:\.(\d+)(?:\.(\d+))?)?} - - class << self - private - - def define_divider_methods(divider) - define_divider_deletion_method(divider) - define_divider_conversion_methods(divider) - end +module Hbc + class DSL + class Version < ::String + DIVIDERS = { + "." => :dots, + "-" => :hyphens, + "_" => :underscores, + "/" => :slashes, + }.freeze + + DIVIDER_REGEX = %r{(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})} + + MAJOR_MINOR_PATCH_REGEX = %r{^(\d+)(?:\.(\d+)(?:\.(\d+))?)?} + + class << self + private + + def define_divider_methods(divider) + define_divider_deletion_method(divider) + define_divider_conversion_methods(divider) + end + + def define_divider_deletion_method(divider) + method_name = deletion_method_name(divider) + define_method(method_name) do + version { delete(divider) } + end + end + + def deletion_method_name(divider) + "no_#{DIVIDERS[divider]}" + end + + def define_divider_conversion_methods(left_divider) + (DIVIDERS.keys - [left_divider]).each do |right_divider| + define_divider_conversion_method(left_divider, right_divider) + end + end + + def define_divider_conversion_method(left_divider, right_divider) + method_name = conversion_method_name(left_divider, right_divider) + define_method(method_name) do + version { gsub(left_divider, right_divider) } + end + end + + def conversion_method_name(left_divider, right_divider) + "#{DIVIDERS[left_divider]}_to_#{DIVIDERS[right_divider]}" + end + end - def define_divider_deletion_method(divider) - method_name = deletion_method_name(divider) - define_method(method_name) do - version { delete(divider) } + DIVIDERS.keys.each do |divider| + define_divider_methods(divider) end - end - def deletion_method_name(divider) - "no_#{DIVIDERS[divider]}" - end + attr_reader :raw_version - def define_divider_conversion_methods(left_divider) - (DIVIDERS.keys - [left_divider]).each do |right_divider| - define_divider_conversion_method(left_divider, right_divider) + def initialize(raw_version) + @raw_version = raw_version + super(raw_version.to_s) end - end - def define_divider_conversion_method(left_divider, right_divider) - method_name = conversion_method_name(left_divider, right_divider) - define_method(method_name) do - version { gsub(left_divider, right_divider) } + def latest? + to_s == "latest" end - end - def conversion_method_name(left_divider, right_divider) - "#{DIVIDERS[left_divider]}_to_#{DIVIDERS[right_divider]}" - end - end - - DIVIDERS.keys.each do |divider| - define_divider_methods(divider) - end - - attr_reader :raw_version - - def initialize(raw_version) - @raw_version = raw_version - super(raw_version.to_s) - end - - def latest? - to_s == "latest" - end - - def major - version { slice(MAJOR_MINOR_PATCH_REGEX, 1) } - end + def major + version { slice(MAJOR_MINOR_PATCH_REGEX, 1) } + end - def minor - version { slice(MAJOR_MINOR_PATCH_REGEX, 2) } - end + def minor + version { slice(MAJOR_MINOR_PATCH_REGEX, 2) } + end - def patch - version { slice(MAJOR_MINOR_PATCH_REGEX, 3) } - end + def patch + version { slice(MAJOR_MINOR_PATCH_REGEX, 3) } + end - def major_minor - version { [major, minor].reject(&:empty?).join(".") } - end + def major_minor + version { [major, minor].reject(&:empty?).join(".") } + end - def major_minor_patch - version { [major, minor, patch].reject(&:empty?).join(".") } - end + def major_minor_patch + version { [major, minor, patch].reject(&:empty?).join(".") } + end - def before_comma - version { split(",", 2)[0] } - end + def before_comma + version { split(",", 2)[0] } + end - def after_comma - version { split(",", 2)[1] } - end + def after_comma + version { split(",", 2)[1] } + end - def before_colon - version { split(":", 2)[0] } - end + def before_colon + version { split(":", 2)[0] } + end - def after_colon - version { split(":", 2)[1] } - end + def after_colon + version { split(":", 2)[1] } + end - def no_dividers - version { gsub(DIVIDER_REGEX, "") } - end + def no_dividers + version { gsub(DIVIDER_REGEX, "") } + end - private + private - def version - return self if empty? || latest? - self.class.new(yield) + def version + return self if empty? || latest? + self.class.new(yield) + end + end end end |
