Merge pull request #1266 from reitermarkus/rubocop

Remove Cask’s RuboCop configuration.
This commit is contained in:
Markus Reiter 2016-10-23 16:19:20 +02:00 committed by GitHub
commit 19347f3b87
98 changed files with 922 additions and 1055 deletions

View File

@ -1,5 +1,7 @@
AllCops:
TargetRubyVersion: 2.0
Exclude:
- '**/Casks/**/*'
Metrics/AbcSize:
Enabled: false

View File

@ -6,9 +6,14 @@ AllCops:
Include:
- '**/.simplecov'
Exclude:
- 'cask/**/*'
- '**/Casks/**/*'
- '**/vendor/**/*'
Style/BlockDelimiters:
Exclude:
- '**/cask/spec/**/*'
- '**/cask/test/**/*'
# so many of these in formulae but none in here
Lint/AmbiguousRegexpLiteral:
Enabled: true

View File

@ -1,131 +0,0 @@
AllCops:
TargetRubyVersion: 2.0
Exclude:
- '**/.simplecov'
- '**/Casks/**/*'
- '**/vendor/**/*'
Metrics/AbcSize:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
CountComments: false
Exclude:
- 'lib/hbc/locations.rb'
- 'lib/hbc/macos.rb'
- 'lib/hbc/utils.rb'
Metrics/PerceivedComplexity:
Enabled: false
Style/AlignHash:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
Style/BarePercentLiterals:
EnforcedStyle: percent_q
Style/BlockDelimiters:
EnforcedStyle: semantic
FunctionalMethods:
- expect
- let
- let!
- subject
- watch
- inject
- map
- map!
- collect
- collect!
- reject
- reject!
- delete_if
- with_object
ProceduralMethods:
- after
- at_exit
- before
- benchmark
- bm
- bmbm
- capture_io
- capture_output
- capture_subprocess_io
- chdir
- context
- create
- define_method
- define_singleton_method
- each_with_object
- fork
- measure
- new
- open
- realtime
- shutup
- tap
- each
- reverse_each
IgnoredMethods:
- it
- its
- lambda
- proc
Style/ClassAndModuleChildren:
EnforcedStyle: nested
Style/Documentation:
Enabled: false
Style/FileName:
Regex: !ruby/regexp /^((([\dA-Z]+|[\da-z]+)(_([\dA-Z]+|[\da-z]+))*|(\-\-)?([\dA-Z]+|[\da-z]+)(-([\dA-Z]+|[\da-z]+))*))(\.rb)?$/
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys
Style/IndentArray:
EnforcedStyle: align_brackets
Style/IndentHash:
EnforcedStyle: align_braces
Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%': '{}'
'%i': '{}'
'%q': '{}'
'%Q': '{}'
'%r': '{}'
'%s': '()'
'%w': '[]'
'%W': '[]'
'%x': '()'
Style/RaiseArgs:
EnforcedStyle: exploded
Style/RegexpLiteral:
EnforcedStyle: percent_r
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: comma

View File

@ -4,7 +4,7 @@ module Hbc
module Artifact
class AbstractFlightBlock < Base
def self.artifact_dsl_key
super.to_s.sub(%r{_block$}, "").to_sym
super.to_s.sub(/_block$/, "").to_sym
end
def self.uninstall_artifact_dsl_key

View File

@ -2,15 +2,15 @@ module Hbc
module Artifact
class Base
def self.artifact_name
@artifact_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1_\2').downcase
@artifact_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
end
def self.artifact_english_name
@artifact_english_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1 \2')
@artifact_english_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2')
end
def self.artifact_english_article
@artifact_english_article ||= artifact_english_name =~ %r{^[aeiou]}i ? "an" : "a"
@artifact_english_article ||= artifact_english_name =~ /^[aeiou]/i ? "an" : "a"
end
def self.artifact_dsl_key

View File

@ -58,8 +58,8 @@ module Hbc
def warning_target_exists
message_parts = [
"It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'",
]
"It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'",
]
yield(message_parts) if block_given?
message_parts.join("; ")
end

View File

@ -47,9 +47,9 @@ module Hbc
raise CaskError, "pkg source file not found: '#{source}'"
end
args = [
"-pkg", source,
"-target", "/"
]
"-pkg", source,
"-target", "/"
]
args << "-verboseR" if Hbc.verbose
args << "-allowUntrusted" if pkg_install_opts :allow_untrusted
@command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true)

View File

@ -15,7 +15,7 @@ module Hbc
attr_reader :source, :target
def printable_target
target.to_s.sub(%r{^#{ENV['HOME']}(#{File::SEPARATOR}|$)}, "~/")
target.to_s.sub(/^#{ENV['HOME']}(#{File::SEPARATOR}|$)/, "~/")
end
ALT_NAME_ATTRIBUTE = "com.apple.metadata:kMDItemAlternateNames".freeze
@ -28,10 +28,10 @@ module Hbc
odebug "Adding #{ALT_NAME_ATTRIBUTE} metadata"
altnames = @command.run("/usr/bin/xattr",
args: ["-p", ALT_NAME_ATTRIBUTE, file.to_s],
print_stderr: false).stdout.sub(%r{\A\((.*)\)\Z}, '\1')
print_stderr: false).stdout.sub(/\A\((.*)\)\Z/, '\1')
odebug "Existing metadata is: '#{altnames}'"
altnames.concat(", ") unless altnames.empty?
altnames.concat(%Q{"#{altname}"})
altnames.concat(%Q("#{altname}"))
altnames = "(#{altnames})"
# Some packges are shipped as u=rx (e.g. Bitcoin Core)

View File

@ -61,10 +61,10 @@ module Hbc
"#{printable_target} -> #{target.readlink} (#{target.readlink.abv})"
else
string = if self.class.islink?(target)
"#{printable_target} -> #{target.readlink}"
else
printable_target
end
"#{printable_target} -> #{target.readlink}"
else
printable_target
end
Formatter.error(string, label: "Broken Link")
end

View File

@ -11,32 +11,32 @@ module Hbc
PATH_ARG_SLICE_SIZE = 500
ORDERED_DIRECTIVES = [
:early_script,
:launchctl,
:quit,
:signal,
:login_item,
:kext,
:script,
:pkgutil,
:delete,
:trash,
:rmdir,
].freeze
:early_script,
:launchctl,
:quit,
:signal,
:login_item,
:kext,
:script,
:pkgutil,
:delete,
:trash,
:rmdir,
].freeze
# TODO: these methods were consolidated here from separate
# sources and should be refactored for consistency
def self.expand_path_strings(path_strings)
path_strings.map { |path_string|
path_strings.map do |path_string|
path_string.start_with?("~") ? Pathname.new(path_string).expand_path : Pathname.new(path_string)
}
end
end
def self.remove_relative_path_strings(action, path_strings)
relative = path_strings.map { |path_string|
relative = path_strings.map do |path_string|
path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string)
}.compact
end.compact
relative.each do |path_string|
opoo "Skipping #{action} for relative path #{path_string}"
end
@ -44,9 +44,9 @@ module Hbc
end
def self.remove_undeletable_path_strings(action, path_strings)
undeletable = path_strings.map { |path_string|
undeletable = path_strings.map do |path_string|
path_string if MacOS.undeletable?(Pathname.new(path_string))
}.compact
end.compact
undeletable.each do |path_string|
opoo "Skipping #{action} for undeletable path #{path_string}"
end
@ -87,7 +87,7 @@ module Hbc
def warn_for_unknown_directives(directives)
unknown_keys = directives.keys - ORDERED_DIRECTIVES
return if unknown_keys.empty?
opoo %Q{Unknown arguments to #{stanza} -- #{unknown_keys.inspect}. Running "brew update; brew cleanup; brew cask cleanup" will likely fix it.}
opoo %Q(Unknown arguments to #{stanza} -- #{unknown_keys.inspect}. Running "brew update; brew cleanup; brew cask cleanup" will likely fix it.)
end
# Preserve prior functionality of script which runs first. Should rarely be needed.
@ -103,7 +103,7 @@ module Hbc
ohai "Removing launchctl service #{service}"
[false, true].each do |with_sudo|
plist_status = @command.run("/bin/launchctl", args: ["list", service], sudo: with_sudo, print_stderr: false).stdout
if plist_status =~ %r{^\{}
if plist_status =~ /^\{/
@command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo)
sleep 1
end
@ -129,7 +129,7 @@ module Hbc
ohai "Quitting application ID #{id}"
num_running = count_running_processes(id)
next unless num_running > 0
@command.run!("/usr/bin/osascript", args: ["-e", %Q{tell application id "#{id}" to quit}], sudo: true)
@command.run!("/usr/bin/osascript", args: ["-e", %Q(tell application id "#{id}" to quit)], sudo: true)
sleep 3
end
end
@ -156,23 +156,23 @@ module Hbc
def count_running_processes(bundle_id)
@command.run!("/usr/bin/osascript",
args: ["-e", %Q{tell application "System Events" to count processes whose bundle identifier is "#{bundle_id}"}],
args: ["-e", %Q(tell application "System Events" to count processes whose bundle identifier is "#{bundle_id}")],
sudo: true).stdout.to_i
end
def get_unix_pids(bundle_id)
pid_string = @command.run!("/usr/bin/osascript",
args: ["-e", %Q{tell application "System Events" to get the unix id of every process whose bundle identifier is "#{bundle_id}"}],
args: ["-e", %Q(tell application "System Events" to get the unix id of every process whose bundle identifier is "#{bundle_id}")],
sudo: true).stdout.chomp
return [] unless pid_string =~ %r{\A\d+(?:\s*,\s*\d+)*\Z} # sanity check
pid_string.split(%r{\s*,\s*}).map(&:strip).map(&:to_i)
return [] unless pid_string =~ /\A\d+(?:\s*,\s*\d+)*\Z/ # sanity check
pid_string.split(/\s*,\s*/).map(&:strip).map(&:to_i)
end
def uninstall_login_item(directives)
Array(directives[:login_item]).each do |name|
ohai "Removing login item #{name}"
@command.run!("/usr/bin/osascript",
args: ["-e", %Q{tell application "System Events" to delete every login item whose name is "#{name}"}],
args: ["-e", %Q(tell application "System Events" to delete every login item whose name is "#{name}")],
sudo: false)
sleep 1
end

View File

@ -47,7 +47,7 @@ module Hbc
def check_required_stanzas
odebug "Auditing required stanzas"
%i{version sha256 url homepage}.each do |sym|
[:version, :sha256, :url, :homepage].each do |sym|
add_error "a #{sym} stanza is required" unless cask.send(sym)
end
add_error "at least one name stanza is required" if cask.name.empty?
@ -84,7 +84,7 @@ module Hbc
def check_sha256_actually_256(sha256: cask.sha256, stanza: "sha256")
odebug "Verifying #{stanza} string is a legal SHA-256 digest"
return unless sha256.is_a?(String)
return if sha256.length == 64 && sha256[%r{^[0-9a-f]+$}i]
return if sha256.length == 64 && sha256[/^[0-9a-f]+$/i]
add_error "#{stanza} string must be of 64 hexadecimal characters"
end
@ -162,7 +162,7 @@ module Hbc
end
def bad_sourceforge_url?
bad_url_format?(%r{sourceforge},
bad_url_format?(/sourceforge/,
[
%r{\Ahttps://sourceforge\.net/projects/[^/]+/files/latest/download\Z},
%r{\Ahttps://downloads\.sourceforge\.net/(?!(project|sourceforge)\/)},
@ -174,7 +174,7 @@ module Hbc
end
def bad_osdn_url?
bad_url_format?(%r{osd}, [%r{\Ahttps?://([^/]+.)?dl\.osdn\.jp/}])
bad_url_format?(/osd/, [%r{\Ahttps?://([^/]+.)?dl\.osdn\.jp/}])
end
def check_generic_artifacts

View File

@ -2,16 +2,16 @@ module Hbc
class Auditor
def self.audit(cask, audit_download: false, check_token_conflicts: false)
if !ARGV.value("language") &&
languages_blocks = cask.instance_variable_get(:@dsl).instance_variable_get(:@language_blocks)
languages_blocks = cask.instance_variable_get(:@dsl).instance_variable_get(:@language_blocks)
begin
saved_languages = MacOS.instance_variable_get(:@languages)
languages_blocks.keys.map { |languages|
languages_blocks.keys.map do |languages|
ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.join(", ")}"
MacOS.instance_variable_set(:@languages, languages)
audit_cask_instance(Hbc.load(cask.sourcefile_path), audit_download, check_token_conflicts)
CLI::Cleanup.run(cask.token) if audit_download
}.all?
end.all?
ensure
MacOS.instance_variable_set(:@languages, saved_languages)
end

View File

@ -17,7 +17,7 @@ module Hbc
file = symlink.readlink
new_name = file.basename
.sub(%r{\-((?:(\d|#{DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x,
.sub(/\-((?:(\d|#{DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$/x,
'--\1')
renamed_file = Hbc.cache.join(new_name)

View File

@ -11,10 +11,9 @@ module Hbc
@token = token
@sourcefile_path = sourcefile_path
@dsl = dsl || DSL.new(@token)
if block_given?
@dsl.instance_eval(&block)
@dsl.language_eval
end
return unless block_given?
@dsl.instance_eval(&block)
@dsl.language_eval
end
DSL::DSL_METHODS.each do |method_name|
@ -38,12 +37,12 @@ module Hbc
raise CaskError, "Cannot create metadata path when timestamp is :latest"
end
path = if timestamp == :latest
Pathname.glob(metadata_versioned_container_path.join("*")).sort.last
elsif timestamp == :now
Utils.nowstamp_metadata_path(metadata_versioned_container_path)
else
metadata_versioned_container_path.join(timestamp)
end
Pathname.glob(metadata_versioned_container_path.join("*")).sort.last
elsif timestamp == :now
Utils.nowstamp_metadata_path(metadata_versioned_container_path)
else
metadata_versioned_container_path.join(timestamp)
end
if create
odebug "Creating metadata directory #{path}"
FileUtils.mkdir_p path

View File

@ -12,7 +12,7 @@ module Hbc
def graph_dependencies
deps_in = ->(csk) { csk.depends_on ? csk.depends_on.cask || [] : [] }
walk = lambda { |acc, deps|
walk = lambda do |acc, deps|
deps.each do |dep|
next if acc.key?(dep)
succs = deps_in.call Hbc.load(dep)
@ -20,7 +20,7 @@ module Hbc
walk.call(acc, succs)
end
acc
}
end
graphed = walk.call({}, @cask.depends_on.cask)
TopologicalHash[graphed]

View File

@ -8,7 +8,7 @@ module Hbc
dsl = DSL::Caveats.new(cask)
retval = dsl.instance_eval(&@block)
return if retval.nil?
puts retval.to_s.sub(%r{[\r\n \t]*\Z}, "\n\n")
puts retval.to_s.sub(/[\r\n \t]*\Z/, "\n\n")
end
end
end

View File

@ -31,51 +31,50 @@ require "hbc/cli/internal_stanza"
module Hbc
class CLI
ALIASES = {
"ls" => "list",
"homepage" => "home",
"-S" => "search", # verb starting with "-" is questionable
"up" => "update",
"instal" => "install", # gem does the same
"rm" => "uninstall",
"remove" => "uninstall",
"abv" => "info",
"dr" => "doctor",
# aliases from Homebrew that we don't (yet) support
# 'ln' => 'link',
# 'configure' => 'diy',
# '--repo' => '--repository',
# 'environment' => '--env',
# '-c1' => '--config',
}.freeze
"ls" => "list",
"homepage" => "home",
"-S" => "search", # verb starting with "-" is questionable
"up" => "update",
"instal" => "install", # gem does the same
"rm" => "uninstall",
"remove" => "uninstall",
"abv" => "info",
"dr" => "doctor",
# aliases from Homebrew that we don't (yet) support
# 'ln' => 'link',
# 'configure' => 'diy',
# '--repo' => '--repository',
# 'environment' => '--env',
# '-c1' => '--config',
}.freeze
OPTIONS = {
"--caskroom=" => :caskroom=,
"--appdir=" => :appdir=,
"--colorpickerdir=" => :colorpickerdir=,
"--prefpanedir=" => :prefpanedir=,
"--qlplugindir=" => :qlplugindir=,
"--fontdir=" => :fontdir=,
"--servicedir=" => :servicedir=,
"--input_methoddir=" => :input_methoddir=,
"--internet_plugindir=" => :internet_plugindir=,
"--audio_unit_plugindir=" => :audio_unit_plugindir=,
"--vst_plugindir=" => :vst_plugindir=,
"--vst3_plugindir=" => :vst3_plugindir=,
"--screen_saverdir=" => :screen_saverdir=,
}.freeze
"--caskroom=" => :caskroom=,
"--appdir=" => :appdir=,
"--colorpickerdir=" => :colorpickerdir=,
"--prefpanedir=" => :prefpanedir=,
"--qlplugindir=" => :qlplugindir=,
"--fontdir=" => :fontdir=,
"--servicedir=" => :servicedir=,
"--input_methoddir=" => :input_methoddir=,
"--internet_plugindir=" => :internet_plugindir=,
"--audio_unit_plugindir=" => :audio_unit_plugindir=,
"--vst_plugindir=" => :vst_plugindir=,
"--vst3_plugindir=" => :vst3_plugindir=,
"--screen_saverdir=" => :screen_saverdir=,
}.freeze
FLAGS = {
"--no-binaries" => :no_binaries=,
"--debug" => :debug=,
"--verbose" => :verbose=,
"--outdated" => :cleanup_outdated=,
"--help" => :help=,
}.freeze
"--no-binaries" => :no_binaries=,
"--debug" => :debug=,
"--verbose" => :verbose=,
"--outdated" => :cleanup_outdated=,
"--help" => :help=,
}.freeze
def self.command_classes
@command_classes ||= self.constants
.map(&method(:const_get))
.select { |sym| sym.respond_to?(:run) }
@command_classes ||= constants.map(&method(:const_get))
.select { |sym| sym.respond_to?(:run) }
end
def self.commands
@ -114,7 +113,7 @@ module Hbc
# for development and troubleshooting
sym = Pathname.new(command.to_s).basename(".rb").to_s.capitalize
klass = begin
self.const_get(sym)
const_get(sym)
rescue NameError
nil
end
@ -129,7 +128,7 @@ module Hbc
exec "brewcask-#{command}", *ARGV[1..-1]
elsif Pathname.new(command.to_s).executable? &&
command.to_s.include?("/") &&
!command.to_s.match(%r{\.rb$})
!command.to_s.match(/\.rb$/)
# arbitrary external executable with literal path, useful
# for development and troubleshooting
exec command, *ARGV[1..-1]
@ -163,7 +162,7 @@ module Hbc
cask_taps = {}
cask_list.each do |c|
user, repo, token = c.split "/"
repo.sub!(%r{^homebrew-}i, "")
repo.sub!(/^homebrew-/i, "")
cask_taps[token] ||= []
cask_taps[token].push "#{user}/#{repo}"
end
@ -266,7 +265,7 @@ module Hbc
next unless klass.visible
puts " #{klass.command_name.ljust(max_command_len)} #{_help_for(klass)}"
end
puts %Q{\nSee also "man brew-cask"}
puts %Q(\nSee also "man brew-cask")
end
def help

View File

@ -2,7 +2,7 @@ module Hbc
class CLI
class Base
def self.command_name
@command_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1_\2').downcase
@command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
end
def self.visible

View File

@ -5,7 +5,7 @@ module Hbc
cask_tokens = cask_tokens_from(args)
raise CaskUnspecifiedError if cask_tokens.empty?
# only respects the first argument
cask_token = cask_tokens.first.sub(%r{\.rb$}i, "")
cask_token = cask_tokens.first.sub(/\.rb$/i, "")
cask_path = Hbc.path(cask_token)
raise CaskUnavailableError, cask_token.to_s unless cask_path.exist?
puts File.open(cask_path, &:read)

View File

@ -72,14 +72,14 @@ module Hbc
ohai message
deletable_cache_files = if tokens.empty?
cache_files
else
start_withs = tokens.map { |token| "#{token}--" }
cache_files
else
start_withs = tokens.map { |token| "#{token}--" }
cache_files.select { |path|
path.basename.to_s.start_with?(*start_withs)
}
end
cache_files.select do |path|
path.basename.to_s.start_with?(*start_withs)
end
end
delete_paths(deletable_cache_files)
end

View File

@ -4,7 +4,7 @@ module Hbc
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise CaskUnspecifiedError if cask_tokens.empty?
cask_token = cask_tokens.first.sub(%r{\.rb$}i, "")
cask_token = cask_tokens.first.sub(/\.rb$/i, "")
cask_path = Hbc.path(cask_token)
odebug "Creating Cask #{cask_token}"

View File

@ -53,7 +53,7 @@ module Hbc
args: %w[config --get remote.origin.url],
print_stderr: false).stdout.strip
end
if homebrew_origin !~ %r{\S}
if homebrew_origin !~ /\S/
homebrew_origin = "#{none_string} #{error_string}"
elsif homebrew_origin !~ %r{(mxcl|Homebrew)/(home)?brew(\.git)?\Z}
homebrew_origin.concat " #{error_string "warning: nonstandard origin"}"
@ -78,8 +78,8 @@ module Hbc
def self.homebrew_taps
@homebrew_taps ||= if homebrew_repository.respond_to?(:join)
homebrew_repository.join("Library", "Taps")
end
homebrew_repository.join("Library", "Taps")
end
end
def self.homebrew_constants(name)
@ -88,11 +88,11 @@ module Hbc
@homebrew_constants[name] = notfound_string
begin
@homebrew_constants[name] = SystemCommand.run!(Hbc.homebrew_executable,
args: ["--#{name}"],
print_stderr: false)
.stdout
.strip
if @homebrew_constants[name] !~ %r{\S}
args: ["--#{name}"],
print_stderr: false)
.stdout
.strip
if @homebrew_constants[name] !~ /\S/
@homebrew_constants[name] = "#{none_string} #{error_string}"
end
path = Pathname.new(@homebrew_constants[name])
@ -104,7 +104,7 @@ module Hbc
end
def self.locale_variables
ENV.keys.grep(%r{^(?:LC_\S+|LANG|LANGUAGE)\Z}).collect { |v| %Q{#{v}="#{ENV[v]}"} }.sort.join("\n")
ENV.keys.grep(/^(?:LC_\S+|LANG|LANGUAGE)\Z/).collect { |v| %Q(#{v}="#{ENV[v]}") }.sort.join("\n")
end
def self.privileged_uid
@ -118,7 +118,7 @@ module Hbc
end
def self.legacy_tap_pattern
%r{phinze}
/phinze/
end
def self.notfound_string
@ -154,7 +154,7 @@ module Hbc
def self.render_env_var(var)
if ENV.key?(var)
%Q{#{var}="#{ENV[var]}"}
%Q(#{var}="#{ENV[var]}")
else
none_string
end

View File

@ -5,11 +5,11 @@ module Hbc
cask_tokens = cask_tokens_from(args)
raise CaskUnspecifiedError if cask_tokens.empty?
# only respects the first argument
cask_token = cask_tokens.first.sub(%r{\.rb$}i, "")
cask_token = cask_tokens.first.sub(/\.rb$/i, "")
cask_path = Hbc.path(cask_token)
odebug "Opening editor for Cask #{cask_token}"
unless cask_path.exist?
raise CaskUnavailableError, %Q{#{cask_token}, run "brew cask create #{cask_token}" to create a new Cask}
raise CaskUnavailableError, %Q(#{cask_token}, run "brew cask create #{cask_token}" to create a new Cask)
end
exec_editor cask_path
end

View File

@ -53,7 +53,7 @@ module Hbc
def self.repo_info(cask)
user, repo, token = QualifiedToken.parse(Hbc.all_tokens.detect { |t| t.split("/").last == cask.token })
remote_tap = Tap.fetch(user, repo)
return "#{remote_tap.remote}" if remote_tap.custom_remote?
return remote_tap.remote.to_s if remote_tap.custom_remote?
"#{remote_tap.default_remote}/blob/master/Casks/#{token}.rb"
end

View File

@ -1,7 +1,7 @@
module Hbc
class CLI
class InternalAuditModifiedCasks < InternalUseBase
RELEVANT_STANZAS = %i{version sha256 url appcast}.freeze
RELEVANT_STANZAS = [:version, :sha256, :url, :appcast].freeze
class << self
def needs_init?
@ -10,7 +10,7 @@ module Hbc
def run(*args)
commit_range = commit_range(args)
cleanup = args.any? { |a| a =~ %r{^-+c(leanup)?$}i }
cleanup = args.any? { |a| a =~ /^-+c(leanup)?$/i }
new(commit_range, cleanup: cleanup).run
end
@ -109,7 +109,7 @@ module Hbc
def relevant_stanza_modified?(cask_file)
out = git("diff", commit_range, "--", cask_file)
out =~ %r{^\+\s*(#{RELEVANT_STANZAS.join('|')})}
out =~ /^\+\s*(#{RELEVANT_STANZAS.join('|')})/
end
def git(*args)

View File

@ -23,31 +23,31 @@ module Hbc
# TODO: this should be retrievable from Hbc::DSL
ARTIFACTS = Set.new [
:app,
:suite,
:artifact,
:prefpane,
:qlplugin,
:font,
:service,
:colorpicker,
:binary,
:input_method,
:internet_plugin,
:audio_unit_plugin,
:vst_plugin,
:vst3_plugin,
:screen_saver,
:pkg,
:installer,
:stage_only,
:nested_container,
:uninstall,
:postflight,
:uninstall_postflight,
:preflight,
:uninstall_postflight,
]
:app,
:suite,
:artifact,
:prefpane,
:qlplugin,
:font,
:service,
:colorpicker,
:binary,
:input_method,
:internet_plugin,
:audio_unit_plugin,
:vst_plugin,
:vst3_plugin,
:screen_saver,
:pkg,
:installer,
:stage_only,
:nested_container,
:uninstall,
:postflight,
:uninstall_postflight,
:preflight,
:uninstall_postflight,
]
def self.run(*arguments)
table = arguments.include? "--table"

View File

@ -2,7 +2,7 @@ module Hbc
class CLI
class InternalUseBase < Base
def self.command_name
super.sub(%r{^internal_}i, "_")
super.sub(/^internal_/i, "_")
end
def self.visible

View File

@ -21,12 +21,12 @@ module Hbc
all_tokens = CLI.nice_listing(Hbc.all_tokens)
if search_regexp
search_term = arguments.first
partial_matches = all_tokens.grep(%r{#{search_regexp}}i)
partial_matches = all_tokens.grep(/#{search_regexp}/i)
else
simplified_tokens = all_tokens.map { |t| t.sub(%r{^.*\/}, "").gsub(%r{[^a-z0-9]+}i, "") }
simplified_search_term = search_term.sub(%r{\.rb$}i, "").gsub(%r{[^a-z0-9]+}i, "")
exact_match = simplified_tokens.grep(%r{^#{simplified_search_term}$}i) { |t| all_tokens[simplified_tokens.index(t)] }.first
partial_matches = simplified_tokens.grep(%r{#{simplified_search_term}}i) { |t| all_tokens[simplified_tokens.index(t)] }
simplified_tokens = all_tokens.map { |t| t.sub(%r{^.*\/}, "").gsub(/[^a-z0-9]+/i, "") }
simplified_search_term = search_term.sub(/\.rb$/i, "").gsub(/[^a-z0-9]+/i, "")
exact_match = simplified_tokens.grep(/^#{simplified_search_term}$/i) { |t| all_tokens[simplified_tokens.index(t)] }.first
partial_matches = simplified_tokens.grep(/#{simplified_search_term}/i) { |t| all_tokens[simplified_tokens.index(t)] }
partial_matches.delete(exact_match)
end
[exact_match, partial_matches, search_term]

View File

@ -37,12 +37,12 @@ module Hbc
def cask_paths
@cask_paths ||= if cask_tokens.empty?
Hbc.all_tapped_cask_dirs
elsif cask_tokens.any? { |file| File.exist?(file) }
cask_tokens
else
cask_tokens.map { |token| Hbc.path(token) }
end
Hbc.all_tapped_cask_dirs
elsif cask_tokens.any? { |file| File.exist?(file) }
cask_tokens
else
cask_tokens.map { |token| Hbc.path(token) }
end
end
def cask_tokens
@ -67,7 +67,7 @@ module Hbc
end
def fix?
args.any? { |arg| arg =~ %r{--(fix|(auto-?)?correct)} }
args.any? { |arg| arg =~ /--(fix|(auto-?)?correct)/ }
end
end
end

View File

@ -59,7 +59,7 @@ module Hbc
def self.from_type(type)
odebug "Determining which containers to use based on 'container :type'"
begin
self.const_get(type.to_s.split("_").map(&:capitalize).join)
const_get(type.to_s.split("_").map(&:capitalize).join)
rescue NameError
false
end

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Bzip2 < Base
def self.me?(criteria)
criteria.magic_number(%r{^BZh}n)
criteria.magic_number(/^BZh/n)
end
def extract

View File

@ -8,7 +8,7 @@ module Hbc
def self.me?(criteria)
cabextract = which("cabextract")
criteria.magic_number(%r{^MSCF}n) &&
criteria.magic_number(/^MSCF/n) &&
!cabextract.nil? &&
criteria.command.run(cabextract, args: ["-t", "--", criteria.path.to_s]).stderr.empty?
end

View File

@ -9,7 +9,7 @@ module Hbc
end
def extension(regex)
path.extname.sub(%r{^\.}, "") =~ Regexp.new(regex.source, regex.options | Regexp::IGNORECASE)
path.extname.sub(/^\./, "") =~ Regexp.new(regex.source, regex.options | Regexp::IGNORECASE)
end
def magic_number(regex)

View File

@ -78,12 +78,12 @@ module Hbc
end
def bom_filelist_from_path(mount)
Dir.chdir(mount) {
Dir.glob("**/*", File::FNM_DOTMATCH).map { |path|
Dir.chdir(mount) do
Dir.glob("**/*", File::FNM_DOTMATCH).map do |path|
next if skip_path?(Pathname(path))
path == "." ? path : path.prepend("./")
}.compact.join("\n").concat("\n")
}
end.compact.join("\n").concat("\n")
end
end
def skip_path?(path)
@ -91,19 +91,19 @@ module Hbc
end
# unnecessary DMG metadata
DMG_METADATA_FILES = %w[
.background
.com.apple.timemachine.donotpresent
.com.apple.timemachine.supported
.DocumentRevisions-V100
.DS_Store
.fseventsd
.MobileBackups
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
].to_set.freeze
DMG_METADATA_FILES = Set.new %w[
.background
.com.apple.timemachine.donotpresent
.com.apple.timemachine.supported
.DocumentRevisions-V100
.DS_Store
.fseventsd
.MobileBackups
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
].freeze
def dmg_metadata?(path)
relative_root = path.sub(%r{/.*}, "")
@ -117,9 +117,7 @@ module Hbc
def mounts_from_plist(plist)
return [] unless plist.respond_to?(:fetch)
plist.fetch("system-entities", []).map { |entity|
entity["mount-point"]
}.compact
plist.fetch("system-entities", []).map { |e| e["mount-point"] }.compact
end
def assert_mounts_found

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Gzip < Base
def self.me?(criteria)
criteria.magic_number(%r{^\037\213}n)
criteria.magic_number(/^\037\213/n)
end
def extract

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Lzma < Base
def self.me?(criteria)
criteria.magic_number(%r{^\]\000\000\200\000}n)
criteria.magic_number(/^\]\000\000\200\000/n)
end
def extract

View File

@ -4,7 +4,7 @@ module Hbc
class Container
class Otf < Naked
def self.me?(criteria)
criteria.magic_number(%r{^OTTO}n)
criteria.magic_number(/^OTTO/n)
end
end
end

View File

@ -4,9 +4,9 @@ module Hbc
class Container
class Pkg < Naked
def self.me?(criteria)
criteria.extension(%r{m?pkg$}) &&
criteria.extension(/m?pkg$/) &&
(criteria.path.directory? ||
criteria.magic_number(%r{^xar!}n))
criteria.magic_number(/^xar!/n))
end
end
end

View File

@ -4,7 +4,7 @@ module Hbc
class Container
class Rar < GenericUnar
def self.me?(criteria)
criteria.magic_number(%r{^Rar!}n) &&
criteria.magic_number(/^Rar!/n) &&
super
end
end

View File

@ -5,7 +5,7 @@ module Hbc
class SevenZip < GenericUnar
def self.me?(criteria)
# TODO: cover self-extracting archives
criteria.magic_number(%r{^7z}n) &&
criteria.magic_number(/^7z/n) &&
super
end
end

View File

@ -4,7 +4,7 @@ module Hbc
class Container
class Sit < GenericUnar
def self.me?(criteria)
criteria.magic_number(%r{^StuffIt}n) &&
criteria.magic_number(/^StuffIt/n) &&
super
end
end

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Tar < Base
def self.me?(criteria)
criteria.magic_number(%r{^.{257}ustar}n) ||
criteria.magic_number(/^.{257}ustar/n) ||
# or compressed tar (bzip2/gzip/lzma/xz)
IO.popen(["/usr/bin/tar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| !io.read(1).nil? }
end

View File

@ -5,9 +5,9 @@ module Hbc
class Ttf < Naked
def self.me?(criteria)
# TrueType Font
criteria.magic_number(%r{^\000\001\000\000\000}n) ||
criteria.magic_number(/^\000\001\000\000\000/n) ||
# Truetype Font Collection
criteria.magic_number(%r{^ttcf}n)
criteria.magic_number(/^ttcf/n)
end
end
end

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Xar < Base
def self.me?(criteria)
criteria.magic_number(%r{^xar!}n)
criteria.magic_number(/^xar!/n)
end
def extract

View File

@ -4,8 +4,8 @@ module Hbc
class Container
class Xip < Base
def self.me?(criteria)
criteria.magic_number(%r{^xar!}n) &&
IO.popen(["/usr/bin/xar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| io.read =~ %r{\AContent\nMetadata\n\Z} }
criteria.magic_number(/^xar!/n) &&
IO.popen(["/usr/bin/xar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| io.read =~ /\AContent\nMetadata\n\Z/ }
end
def extract

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Xz < Base
def self.me?(criteria)
criteria.magic_number(%r{^\xFD7zXZ\x00}n)
criteria.magic_number(/^\xFD7zXZ\x00/n)
end
def extract

View File

@ -4,7 +4,7 @@ module Hbc
class Container
class Zip < Base
def self.me?(criteria)
criteria.magic_number(%r{^PK(\003\004|\005\006)}n)
criteria.magic_number(/^PK(\003\004|\005\006)/n)
end
def extract

View File

@ -23,13 +23,13 @@ module Hbc
def downloader
@downloader ||= case cask.url.using
when :svn
SubversionDownloadStrategy.new(cask)
when :post
CurlPostDownloadStrategy.new(cask)
else
CurlDownloadStrategy.new(cask)
end
when :svn
SubversionDownloadStrategy.new(cask)
when :post
CurlPostDownloadStrategy.new(cask)
else
CurlDownloadStrategy.new(cask)
end
end
def clear_cache

View File

@ -40,9 +40,9 @@ module Hbc
end
def extract_ref
key = REF_TYPES.find { |type|
key = REF_TYPES.find do |type|
uri_object.respond_to?(type) && uri_object.send(type)
}
end
[key, key ? uri_object.send(key) : nil]
end
@ -74,7 +74,7 @@ module Hbc
end
def temporary_path
@temporary_path ||= tarball_path.sub(%r{$}, ".incomplete")
@temporary_path ||= tarball_path.sub(/$/, ".incomplete")
end
def cached_location
@ -216,7 +216,7 @@ module Hbc
end
def repo_url
`svn info '#{@clone}' 2>/dev/null`.strip[%r{^URL: (.+)$}, 1]
`svn info '#{@clone}' 2>/dev/null`.strip[/^URL: (.+)$/, 1]
end
# super does not provide checks for already-existing downloads
@ -224,7 +224,7 @@ module Hbc
if tarball_path.exist?
puts "Already downloaded: #{tarball_path}"
else
@url = @url.sub(%r{^svn\+}, "") if @url =~ %r{^svn\+http://}
@url = @url.sub(/^svn\+/, "") if @url =~ %r{^svn\+http://}
ohai "Checking out #{@url}"
clear_cache unless @url.chomp("/") == repo_url || quiet_system("svn", "switch", @url, @clone)
@ -291,12 +291,12 @@ module Hbc
def shell_quote(str)
# Oh god escaping shell args.
# See http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/
str.gsub(%r{\\|'}) { |c| "\\#{c}" }
str.gsub(/\\|'/) { |c| "\\#{c}" }
end
def fetch_externals
`svn propget svn:externals '#{shell_quote(@url)}'`.chomp.each_line do |line|
name, url = line.split(%r{\s+})
name, url = line.split(/\s+/)
yield name, url
end
end

View File

@ -19,63 +19,63 @@ require "hbc/dsl/version"
module Hbc
class DSL
ORDINARY_ARTIFACT_TYPES = [
:app,
:artifact,
:audio_unit_plugin,
:binary,
:colorpicker,
:font,
:input_method,
:internet_plugin,
:pkg,
:prefpane,
:qlplugin,
:screen_saver,
:service,
:stage_only,
:suite,
:vst_plugin,
:vst3_plugin,
].freeze
:app,
:artifact,
:audio_unit_plugin,
:binary,
:colorpicker,
:font,
:input_method,
:internet_plugin,
:pkg,
:prefpane,
:qlplugin,
:screen_saver,
:service,
:stage_only,
:suite,
:vst_plugin,
:vst3_plugin,
].freeze
ACTIVATABLE_ARTIFACT_TYPES = ([:installer, *ORDINARY_ARTIFACT_TYPES] - [:stage_only]).freeze
SPECIAL_ARTIFACT_TYPES = [
:uninstall,
:zap,
].freeze
:uninstall,
:zap,
].freeze
ARTIFACT_BLOCK_TYPES = [
:preflight,
:postflight,
:uninstall_preflight,
:uninstall_postflight,
].freeze
:preflight,
:postflight,
:uninstall_preflight,
:uninstall_postflight,
].freeze
DSL_METHODS = Set.new [
:accessibility_access,
:appcast,
:artifacts,
:auto_updates,
:caskroom_path,
:caveats,
:conflicts_with,
:container,
:depends_on,
:gpg,
:homepage,
:language,
:name,
:sha256,
:staged_path,
:url,
:version,
:appdir,
*ORDINARY_ARTIFACT_TYPES,
*ACTIVATABLE_ARTIFACT_TYPES,
*SPECIAL_ARTIFACT_TYPES,
*ARTIFACT_BLOCK_TYPES,
].freeze
:accessibility_access,
:appcast,
:artifacts,
:auto_updates,
:caskroom_path,
:caveats,
:conflicts_with,
:container,
:depends_on,
:gpg,
:homepage,
:language,
:name,
:sha256,
:staged_path,
:url,
:version,
:appdir,
*ORDINARY_ARTIFACT_TYPES,
*ACTIVATABLE_ARTIFACT_TYPES,
*SPECIAL_ARTIFACT_TYPES,
*ARTIFACT_BLOCK_TYPES,
].freeze
attr_reader :token
def initialize(token)
@ -123,9 +123,9 @@ module Hbc
end
MacOS.languages.map(&Locale.method(:parse)).each do |locale|
key = @language_blocks.keys.detect { |strings|
key = @language_blocks.keys.detect do |strings|
strings.any? { |string| locale.include?(string) }
}
end
next if key.nil?
@ -183,8 +183,8 @@ module Hbc
end
SYMBOLIC_VERSIONS = Set.new [
:latest,
]
:latest,
]
def version(arg = nil)
return @version if arg.nil?
@ -194,8 +194,8 @@ module Hbc
end
SYMBOLIC_SHA256S = Set.new [
:no_check,
]
:no_check,
]
def sha256(arg = nil)
return @sha256 if arg.nil?
@ -252,7 +252,7 @@ module Hbc
if block_given?
@caveats << Hbc::Caveats.new(block)
elsif string.any?
@caveats << string.map { |s| s.to_s.sub(%r{[\r\n \t]*\Z}, "\n\n") }
@caveats << string.map { |s| s.to_s.sub(/[\r\n \t]*\Z/, "\n\n") }
end
@caveats
end

View File

@ -16,7 +16,7 @@ module Hbc
def method_missing(method, *)
if method
underscored_class = self.class.name.gsub(%r{([[:lower:]])([[:upper:]][[:lower:]])}, '\1_\2').downcase
underscored_class = self.class.name.gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase
section = underscored_class.downcase.split("::").last
Utils.method_missing_message(method, @cask.to_s, section)
nil

View File

@ -2,13 +2,13 @@ module Hbc
class DSL
class ConflictsWith
VALID_KEYS = Set.new [
:formula,
:cask,
:macos,
:arch,
:x11,
:java,
]
:formula,
:cask,
:macos,
:arch,
:x11,
:java,
]
attr_accessor(*VALID_KEYS)
attr_accessor :pairs

View File

@ -2,9 +2,9 @@ module Hbc
class DSL
class Container
VALID_KEYS = Set.new [
:type,
:nested,
]
:type,
:nested,
]
attr_accessor(*VALID_KEYS)
attr_accessor :pairs

View File

@ -4,40 +4,40 @@ module Hbc
class DSL
class DependsOn
VALID_KEYS = Set.new [
:formula,
:cask,
:macos,
:arch,
:x11,
:java,
].freeze
: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
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
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
@ -62,7 +62,7 @@ module Hbc
begin
if arg.is_a?(Symbol)
Gem::Version.new(@macos_symbols.fetch(arg))
elsif arg =~ %r{^\s*:?([a-z]\S+)\s*$}i
elsif arg =~ /^\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)
@ -86,26 +86,24 @@ module Hbc
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 = if arg.count == 1 && arg.first =~ /^\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)
[*arg].map(&self.class.method(:coerce_os_release)).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
arches = Array(*arg).map do |elt|
elt = elt.to_s.downcase.sub(/^:/, "").tr("-", "_").to_sym
ARCH_SYNONYMS.key?(elt) ? ARCH_SYNONYMS[elt] : elt
}
end
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] })

View File

@ -2,9 +2,9 @@ module Hbc
class DSL
class Gpg
KEY_PARAMETERS = Set.new [
:key_id,
:key_url,
]
:key_id,
:key_url,
]
VALID_PARAMETERS = Set.new []
VALID_PARAMETERS.merge KEY_PARAMETERS
@ -28,7 +28,7 @@ module Hbc
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]
is_valid = id.is_a?(String) && legal_lengths.include?(id.length) && id[/^[0-9a-f]+$/i]
raise "invalid ':key_id' value: '#{id.inspect}'" unless is_valid
is_valid

View File

@ -2,9 +2,9 @@ module Hbc
class DSL
class Installer
VALID_KEYS = Set.new [
:manual,
:script,
]
:manual,
:script,
]
attr_accessor(*VALID_KEYS)

View File

@ -36,7 +36,7 @@ module Hbc
end
def respond_to?(method, include_private = false)
return true if %i{encode_with proxy? to_s type}.include?(method)
return true if [:encode_with, :proxy?, :to_s, :type].include?(method)
return false if method == :to_ary
@resolver.call.respond_to?(method, include_private)
end

View File

@ -2,15 +2,15 @@ module Hbc
class DSL
class Version < ::String
DIVIDERS = {
"." => :dots,
"-" => :hyphens,
"_" => :underscores,
"/" => :slashes,
}.freeze
"." => :dots,
"-" => :hyphens,
"_" => :underscores,
"/" => :slashes,
}.freeze
DIVIDER_REGEX = %r{(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})}
DIVIDER_REGEX = /(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})/
MAJOR_MINOR_PATCH_REGEX = %r{^(\d+)(?:\.(\d+)(?:\.(\d+))?)?}
MAJOR_MINOR_PATCH_REGEX = /^(\d+)(?:\.(\d+)(?:\.(\d+))?)?/
class << self
private

View File

@ -23,7 +23,7 @@ module Hbc
class CaskAlreadyCreatedError < AbstractCaskErrorWithToken
def to_s
%Q{A Cask for #{token} already exists. Run "brew cask cat #{token}" to see it.}
%Q(A Cask for #{token} already exists. Run "brew cask cat #{token}" to see it.)
end
end

View File

@ -5,7 +5,7 @@ module Hbc
TIMEOUT = 10
def self.head(url)
if url.to_s =~ %r{googlecode}
if url.to_s =~ /googlecode/
googlecode_fake_head(url)
else
SystemCommand.run("/usr/bin/curl",
@ -18,7 +18,7 @@ module Hbc
def self.googlecode_fake_head(url)
command = "curl --max-time #{TIMEOUT} --verbose --location '#{url}' | head -n 20 > /dev/null"
stderr = Open3.capture3(command)[1]
stderr.split("\n").grep(%r{^< }).map { |line| line.sub(%r{^< }, "") }.join("\n")
stderr.split("\n").grep(/^< /).map { |line| line.sub(/^< /, "") }.join("\n")
end
end
end

View File

@ -84,10 +84,10 @@ module Hbc
def summary
s = if MacOS.version >= :lion && !ENV["HOMEBREW_NO_EMOJI"]
(ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba") + " "
else
Formatter.headline("Success! ", color: :blue)
end
(ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba") + " "
else
Formatter.headline("Success! ", color: :blue)
end
s << "#{@cask} was successfully installed!"
end
@ -113,10 +113,10 @@ module Hbc
odebug "Extracting primary container"
FileUtils.mkdir_p @cask.staged_path
container = if @cask.container && @cask.container.type
Container.from_type(@cask.container.type)
else
Container.for_path(@downloaded_path, @command)
end
Container.from_type(@cask.container.type)
else
Container.for_path(@downloaded_path, @command)
end
unless container
raise CaskError, "Uh oh, could not figure out how to unpack '#{@downloaded_path}'"
end
@ -171,10 +171,10 @@ module Hbc
def arch_dependencies
return if @cask.depends_on.arch.nil?
@current_arch ||= { type: Hardware::CPU.type, bits: Hardware::CPU.bits }
return if @cask.depends_on.arch.any? { |arch|
return if @cask.depends_on.arch.any? do |arch|
arch[:type] == @current_arch[:type] &&
Array(arch[:bits]).include?(@current_arch[:bits])
}
end
raise CaskError, "Cask #{@cask} depends on hardware architecture being one of [#{@cask.depends_on.arch.map(&:to_s).join(", ")}], but you are running #{@current_arch}"
end
@ -232,16 +232,16 @@ module Hbc
elsif MacOS.version <= :yosemite
@command.run!("/usr/bin/sqlite3",
args: [
Hbc.tcc_db,
"INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL);",
],
Hbc.tcc_db,
"INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL);",
],
sudo: true)
elsif MacOS.version <= :el_capitan
@command.run!("/usr/bin/sqlite3",
args: [
Hbc.tcc_db,
"INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL,NULL);",
],
Hbc.tcc_db,
"INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL,NULL);",
],
sudo: true)
else
opoo <<-EOS.undent
@ -257,9 +257,9 @@ module Hbc
ohai "Disabling accessibility access"
@command.run!("/usr/bin/sqlite3",
args: [
Hbc.tcc_db,
"DELETE FROM access WHERE client='#{bundle_identifier}';",
],
Hbc.tcc_db,
"DELETE FROM access WHERE client='#{bundle_identifier}';",
],
sudo: true)
else
opoo <<-EOS.undent
@ -302,7 +302,7 @@ module Hbc
end
def zap
ohai %Q{Implied "brew cask uninstall #{@cask}"}
ohai %Q(Implied "brew cask uninstall #{@cask}")
uninstall_artifacts
if Artifact::Zap.me?(@cask)
ohai "Dispatching zap stanza"

View File

@ -136,15 +136,15 @@ module Hbc
return query_path if query_path.absolute?
return query_path if query_path.exist? && query_path.extname == ".rb"
query_without_extension = query.sub(%r{\.rb$}i, "")
query_without_extension = query.sub(/\.rb$/i, "")
token_with_tap = if query =~ %r{\A[^/]+/[^/]+/[^/]+\Z}
query_without_extension
else
all_tokens.detect { |tap_and_token|
tap_and_token.split("/")[2] == query_without_extension
}
end
query_without_extension
else
all_tokens.detect do |tap_and_token|
tap_and_token.split("/")[2] == query_without_extension
end
end
if token_with_tap
user, repo, token = token_with_tap.split("/")

View File

@ -7,231 +7,231 @@ module OS
module_function
SYSTEM_DIRS = [
"/",
"/Applications",
"/Applications/Utilities",
"/Incompatible Software",
"/Library",
"/Library/Application Support",
"/Library/Audio",
"/Library/Caches",
"/Library/ColorPickers",
"/Library/ColorSync",
"/Library/Components",
"/Library/Compositions",
"/Library/Contextual Menu Items",
"/Library/CoreMediaIO",
"/Library/Desktop Pictures",
"/Library/Developer",
"/Library/Dictionaries",
"/Library/DirectoryServices",
"/Library/Documentation",
"/Library/Extensions",
"/Library/Filesystems",
"/Library/Fonts",
"/Library/Frameworks",
"/Library/Graphics",
"/Library/Image Capture",
"/Library/Input Methods",
"/Library/Internet Plug-Ins",
"/Library/Java",
"/Library/Keyboard Layouts",
"/Library/Keychains",
"/Library/LaunchAgents",
"/Library/LaunchDaemons",
"/Library/Logs",
"/Library/Messages",
"/Library/Modem Scripts",
"/Library/OpenDirectory",
"/Library/PDF Services",
"/Library/Perl",
"/Library/PreferencePanes",
"/Library/Preferences",
"/Library/Printers",
"/Library/PrivilegedHelperTools",
"/Library/Python",
"/Library/QuickLook",
"/Library/QuickTime",
"/Library/Receipts",
"/Library/Ruby",
"/Library/Sandbox",
"/Library/Screen Savers",
"/Library/ScriptingAdditions",
"/Library/Scripts",
"/Library/Security",
"/Library/Speech",
"/Library/Spelling",
"/Library/Spotlight",
"/Library/StartupItems",
"/Library/SystemProfiler",
"/Library/Updates",
"/Library/User Pictures",
"/Library/Video",
"/Library/WebServer",
"/Library/Widgets",
"/Library/iTunes",
"/Network",
"/System",
"/System/Library",
"/System/Library/Accessibility",
"/System/Library/Accounts",
"/System/Library/Address Book Plug-Ins",
"/System/Library/Assistant",
"/System/Library/Automator",
"/System/Library/BridgeSupport",
"/System/Library/Caches",
"/System/Library/ColorPickers",
"/System/Library/ColorSync",
"/System/Library/Colors",
"/System/Library/Components",
"/System/Library/Compositions",
"/System/Library/CoreServices",
"/System/Library/DTDs",
"/System/Library/DirectoryServices",
"/System/Library/Displays",
"/System/Library/Extensions",
"/System/Library/Filesystems",
"/System/Library/Filters",
"/System/Library/Fonts",
"/System/Library/Frameworks",
"/System/Library/Graphics",
"/System/Library/IdentityServices",
"/System/Library/Image Capture",
"/System/Library/Input Methods",
"/System/Library/InternetAccounts",
"/System/Library/Java",
"/System/Library/KerberosPlugins",
"/System/Library/Keyboard Layouts",
"/System/Library/Keychains",
"/System/Library/LaunchAgents",
"/System/Library/LaunchDaemons",
"/System/Library/LinguisticData",
"/System/Library/LocationBundles",
"/System/Library/LoginPlugins",
"/System/Library/Messages",
"/System/Library/Metadata",
"/System/Library/MonitorPanels",
"/System/Library/OpenDirectory",
"/System/Library/OpenSSL",
"/System/Library/Password Server Filters",
"/System/Library/PerformanceMetrics",
"/System/Library/Perl",
"/System/Library/PreferencePanes",
"/System/Library/Printers",
"/System/Library/PrivateFrameworks",
"/System/Library/QuickLook",
"/System/Library/QuickTime",
"/System/Library/QuickTimeJava",
"/System/Library/Recents",
"/System/Library/SDKSettingsPlist",
"/System/Library/Sandbox",
"/System/Library/Screen Savers",
"/System/Library/ScreenReader",
"/System/Library/ScriptingAdditions",
"/System/Library/ScriptingDefinitions",
"/System/Library/Security",
"/System/Library/Services",
"/System/Library/Sounds",
"/System/Library/Speech",
"/System/Library/Spelling",
"/System/Library/Spotlight",
"/System/Library/StartupItems",
"/System/Library/SyncServices",
"/System/Library/SystemConfiguration",
"/System/Library/SystemProfiler",
"/System/Library/Tcl",
"/System/Library/TextEncodings",
"/System/Library/User Template",
"/System/Library/UserEventPlugins",
"/System/Library/Video",
"/System/Library/WidgetResources",
"/User Information",
"/Users",
"/Volumes",
"/bin",
"/boot",
"/cores",
"/dev",
"/etc",
"/etc/X11",
"/etc/opt",
"/etc/sgml",
"/etc/xml",
"/home",
"/libexec",
"/lost+found",
"/media",
"/mnt",
"/net",
"/opt",
"/private",
"/private/etc",
"/private/tftpboot",
"/private/tmp",
"/private/var",
"/proc",
"/root",
"/sbin",
"/srv",
"/tmp",
"/usr",
"/usr/X11R6",
"/usr/bin",
"/usr/etc",
"/usr/include",
"/usr/lib",
"/usr/libexec",
"/usr/local",
"/usr/local/Cellar",
"/usr/local/Frameworks",
"/usr/local/Library",
"/usr/local/bin",
"/usr/local/etc",
"/usr/local/include",
"/usr/local/lib",
"/usr/local/libexec",
"/usr/local/opt",
"/usr/local/share",
"/usr/local/share/man",
"/usr/local/share/man/man1",
"/usr/local/share/man/man2",
"/usr/local/share/man/man3",
"/usr/local/share/man/man4",
"/usr/local/share/man/man5",
"/usr/local/share/man/man6",
"/usr/local/share/man/man7",
"/usr/local/share/man/man8",
"/usr/local/share/man/man9",
"/usr/local/share/man/mann",
"/usr/local/var",
"/usr/local/var/lib",
"/usr/local/var/lock",
"/usr/local/var/run",
"/usr/sbin",
"/usr/share",
"/usr/share/man",
"/usr/share/man/man1",
"/usr/share/man/man2",
"/usr/share/man/man3",
"/usr/share/man/man4",
"/usr/share/man/man5",
"/usr/share/man/man6",
"/usr/share/man/man7",
"/usr/share/man/man8",
"/usr/share/man/man9",
"/usr/share/man/mann",
"/usr/src",
"/var",
"/var/cache",
"/var/lib",
"/var/lock",
"/var/log",
"/var/mail",
"/var/run",
"/var/spool",
"/var/spool/mail",
"/var/tmp",
]
"/",
"/Applications",
"/Applications/Utilities",
"/Incompatible Software",
"/Library",
"/Library/Application Support",
"/Library/Audio",
"/Library/Caches",
"/Library/ColorPickers",
"/Library/ColorSync",
"/Library/Components",
"/Library/Compositions",
"/Library/Contextual Menu Items",
"/Library/CoreMediaIO",
"/Library/Desktop Pictures",
"/Library/Developer",
"/Library/Dictionaries",
"/Library/DirectoryServices",
"/Library/Documentation",
"/Library/Extensions",
"/Library/Filesystems",
"/Library/Fonts",
"/Library/Frameworks",
"/Library/Graphics",
"/Library/Image Capture",
"/Library/Input Methods",
"/Library/Internet Plug-Ins",
"/Library/Java",
"/Library/Keyboard Layouts",
"/Library/Keychains",
"/Library/LaunchAgents",
"/Library/LaunchDaemons",
"/Library/Logs",
"/Library/Messages",
"/Library/Modem Scripts",
"/Library/OpenDirectory",
"/Library/PDF Services",
"/Library/Perl",
"/Library/PreferencePanes",
"/Library/Preferences",
"/Library/Printers",
"/Library/PrivilegedHelperTools",
"/Library/Python",
"/Library/QuickLook",
"/Library/QuickTime",
"/Library/Receipts",
"/Library/Ruby",
"/Library/Sandbox",
"/Library/Screen Savers",
"/Library/ScriptingAdditions",
"/Library/Scripts",
"/Library/Security",
"/Library/Speech",
"/Library/Spelling",
"/Library/Spotlight",
"/Library/StartupItems",
"/Library/SystemProfiler",
"/Library/Updates",
"/Library/User Pictures",
"/Library/Video",
"/Library/WebServer",
"/Library/Widgets",
"/Library/iTunes",
"/Network",
"/System",
"/System/Library",
"/System/Library/Accessibility",
"/System/Library/Accounts",
"/System/Library/Address Book Plug-Ins",
"/System/Library/Assistant",
"/System/Library/Automator",
"/System/Library/BridgeSupport",
"/System/Library/Caches",
"/System/Library/ColorPickers",
"/System/Library/ColorSync",
"/System/Library/Colors",
"/System/Library/Components",
"/System/Library/Compositions",
"/System/Library/CoreServices",
"/System/Library/DTDs",
"/System/Library/DirectoryServices",
"/System/Library/Displays",
"/System/Library/Extensions",
"/System/Library/Filesystems",
"/System/Library/Filters",
"/System/Library/Fonts",
"/System/Library/Frameworks",
"/System/Library/Graphics",
"/System/Library/IdentityServices",
"/System/Library/Image Capture",
"/System/Library/Input Methods",
"/System/Library/InternetAccounts",
"/System/Library/Java",
"/System/Library/KerberosPlugins",
"/System/Library/Keyboard Layouts",
"/System/Library/Keychains",
"/System/Library/LaunchAgents",
"/System/Library/LaunchDaemons",
"/System/Library/LinguisticData",
"/System/Library/LocationBundles",
"/System/Library/LoginPlugins",
"/System/Library/Messages",
"/System/Library/Metadata",
"/System/Library/MonitorPanels",
"/System/Library/OpenDirectory",
"/System/Library/OpenSSL",
"/System/Library/Password Server Filters",
"/System/Library/PerformanceMetrics",
"/System/Library/Perl",
"/System/Library/PreferencePanes",
"/System/Library/Printers",
"/System/Library/PrivateFrameworks",
"/System/Library/QuickLook",
"/System/Library/QuickTime",
"/System/Library/QuickTimeJava",
"/System/Library/Recents",
"/System/Library/SDKSettingsPlist",
"/System/Library/Sandbox",
"/System/Library/Screen Savers",
"/System/Library/ScreenReader",
"/System/Library/ScriptingAdditions",
"/System/Library/ScriptingDefinitions",
"/System/Library/Security",
"/System/Library/Services",
"/System/Library/Sounds",
"/System/Library/Speech",
"/System/Library/Spelling",
"/System/Library/Spotlight",
"/System/Library/StartupItems",
"/System/Library/SyncServices",
"/System/Library/SystemConfiguration",
"/System/Library/SystemProfiler",
"/System/Library/Tcl",
"/System/Library/TextEncodings",
"/System/Library/User Template",
"/System/Library/UserEventPlugins",
"/System/Library/Video",
"/System/Library/WidgetResources",
"/User Information",
"/Users",
"/Volumes",
"/bin",
"/boot",
"/cores",
"/dev",
"/etc",
"/etc/X11",
"/etc/opt",
"/etc/sgml",
"/etc/xml",
"/home",
"/libexec",
"/lost+found",
"/media",
"/mnt",
"/net",
"/opt",
"/private",
"/private/etc",
"/private/tftpboot",
"/private/tmp",
"/private/var",
"/proc",
"/root",
"/sbin",
"/srv",
"/tmp",
"/usr",
"/usr/X11R6",
"/usr/bin",
"/usr/etc",
"/usr/include",
"/usr/lib",
"/usr/libexec",
"/usr/local",
"/usr/local/Cellar",
"/usr/local/Frameworks",
"/usr/local/Library",
"/usr/local/bin",
"/usr/local/etc",
"/usr/local/include",
"/usr/local/lib",
"/usr/local/libexec",
"/usr/local/opt",
"/usr/local/share",
"/usr/local/share/man",
"/usr/local/share/man/man1",
"/usr/local/share/man/man2",
"/usr/local/share/man/man3",
"/usr/local/share/man/man4",
"/usr/local/share/man/man5",
"/usr/local/share/man/man6",
"/usr/local/share/man/man7",
"/usr/local/share/man/man8",
"/usr/local/share/man/man9",
"/usr/local/share/man/mann",
"/usr/local/var",
"/usr/local/var/lib",
"/usr/local/var/lock",
"/usr/local/var/run",
"/usr/sbin",
"/usr/share",
"/usr/share/man",
"/usr/share/man/man1",
"/usr/share/man/man2",
"/usr/share/man/man3",
"/usr/share/man/man4",
"/usr/share/man/man5",
"/usr/share/man/man6",
"/usr/share/man/man7",
"/usr/share/man/man8",
"/usr/share/man/man9",
"/usr/share/man/mann",
"/usr/src",
"/var",
"/var/cache",
"/var/lib",
"/var/lock",
"/var/log",
"/var/mail",
"/var/run",
"/var/spool",
"/var/spool/mail",
"/var/tmp",
]
.map(&method(:Pathname))
.to_set
.freeze
@ -239,131 +239,131 @@ module OS
# TODO: There should be a way to specify a containing
# directory under which nothing can be deleted.
UNDELETABLE_DIRS = [
"~/",
"~/Applications",
"~/Desktop",
"~/Documents",
"~/Downloads",
"~/Mail",
"~/Movies",
"~/Music",
"~/Music/iTunes",
"~/Music/iTunes/iTunes Music",
"~/Music/iTunes/Album Artwork",
"~/News",
"~/Pictures",
"~/Pictures/Desktops",
"~/Pictures/Photo Booth",
"~/Pictures/iChat Icons",
"~/Pictures/iPhoto Library",
"~/Public",
"~/Sites",
"~/Library",
"~/Library/.localized",
"~/Library/Accessibility",
"~/Library/Accounts",
"~/Library/Address Book Plug-Ins",
"~/Library/Application Scripts",
"~/Library/Application Support",
"~/Library/Application Support/Apple",
"~/Library/Application Support/com.apple.AssistiveControl",
"~/Library/Application Support/com.apple.QuickLook",
"~/Library/Application Support/com.apple.TCC",
"~/Library/Assistants",
"~/Library/Audio",
"~/Library/Automator",
"~/Library/Autosave Information",
"~/Library/Caches",
"~/Library/Calendars",
"~/Library/ColorPickers",
"~/Library/ColorSync",
"~/Library/Colors",
"~/Library/Components",
"~/Library/Compositions",
"~/Library/Containers",
"~/Library/Contextual Menu Items",
"~/Library/Cookies",
"~/Library/DTDs",
"~/Library/Desktop Pictures",
"~/Library/Developer",
"~/Library/Dictionaries",
"~/Library/DirectoryServices",
"~/Library/Displays",
"~/Library/Documentation",
"~/Library/Extensions",
"~/Library/Favorites",
"~/Library/FileSync",
"~/Library/Filesystems",
"~/Library/Filters",
"~/Library/FontCollections",
"~/Library/Fonts",
"~/Library/Frameworks",
"~/Library/GameKit",
"~/Library/Graphics",
"~/Library/Group Containers",
"~/Library/Icons",
"~/Library/IdentityServices",
"~/Library/Image Capture",
"~/Library/Images",
"~/Library/Input Methods",
"~/Library/Internet Plug-Ins",
"~/Library/InternetAccounts",
"~/Library/iTunes",
"~/Library/KeyBindings",
"~/Library/Keyboard Layouts",
"~/Library/Keychains",
"~/Library/LaunchAgents",
"~/Library/LaunchDaemons",
"~/Library/LocationBundles",
"~/Library/LoginPlugins",
"~/Library/Logs",
"~/Library/Mail",
"~/Library/Mail Downloads",
"~/Library/Messages",
"~/Library/Metadata",
"~/Library/Mobile Documents",
"~/Library/MonitorPanels",
"~/Library/OpenDirectory",
"~/Library/PDF Services",
"~/Library/PhonePlugins",
"~/Library/Phones",
"~/Library/PreferencePanes",
"~/Library/Preferences",
"~/Library/Printers",
"~/Library/PrivateFrameworks",
"~/Library/PubSub",
"~/Library/QuickLook",
"~/Library/QuickTime",
"~/Library/Receipts",
"~/Library/Recent Servers",
"~/Library/Recents",
"~/Library/Safari",
"~/Library/Saved Application State",
"~/Library/Screen Savers",
"~/Library/ScreenReader",
"~/Library/ScriptingAdditions",
"~/Library/ScriptingDefinitions",
"~/Library/Scripts",
"~/Library/Security",
"~/Library/Services",
"~/Library/Sounds",
"~/Library/Speech",
"~/Library/Spelling",
"~/Library/Spotlight",
"~/Library/StartupItems",
"~/Library/StickiesDatabase",
"~/Library/Sync Services",
"~/Library/SyncServices",
"~/Library/SyncedPreferences",
"~/Library/TextEncodings",
"~/Library/User Pictures",
"~/Library/Video",
"~/Library/Voices",
"~/Library/WebKit",
"~/Library/WidgetResources",
"~/Library/Widgets",
"~/Library/Workflows",
]
"~/",
"~/Applications",
"~/Desktop",
"~/Documents",
"~/Downloads",
"~/Mail",
"~/Movies",
"~/Music",
"~/Music/iTunes",
"~/Music/iTunes/iTunes Music",
"~/Music/iTunes/Album Artwork",
"~/News",
"~/Pictures",
"~/Pictures/Desktops",
"~/Pictures/Photo Booth",
"~/Pictures/iChat Icons",
"~/Pictures/iPhoto Library",
"~/Public",
"~/Sites",
"~/Library",
"~/Library/.localized",
"~/Library/Accessibility",
"~/Library/Accounts",
"~/Library/Address Book Plug-Ins",
"~/Library/Application Scripts",
"~/Library/Application Support",
"~/Library/Application Support/Apple",
"~/Library/Application Support/com.apple.AssistiveControl",
"~/Library/Application Support/com.apple.QuickLook",
"~/Library/Application Support/com.apple.TCC",
"~/Library/Assistants",
"~/Library/Audio",
"~/Library/Automator",
"~/Library/Autosave Information",
"~/Library/Caches",
"~/Library/Calendars",
"~/Library/ColorPickers",
"~/Library/ColorSync",
"~/Library/Colors",
"~/Library/Components",
"~/Library/Compositions",
"~/Library/Containers",
"~/Library/Contextual Menu Items",
"~/Library/Cookies",
"~/Library/DTDs",
"~/Library/Desktop Pictures",
"~/Library/Developer",
"~/Library/Dictionaries",
"~/Library/DirectoryServices",
"~/Library/Displays",
"~/Library/Documentation",
"~/Library/Extensions",
"~/Library/Favorites",
"~/Library/FileSync",
"~/Library/Filesystems",
"~/Library/Filters",
"~/Library/FontCollections",
"~/Library/Fonts",
"~/Library/Frameworks",
"~/Library/GameKit",
"~/Library/Graphics",
"~/Library/Group Containers",
"~/Library/Icons",
"~/Library/IdentityServices",
"~/Library/Image Capture",
"~/Library/Images",
"~/Library/Input Methods",
"~/Library/Internet Plug-Ins",
"~/Library/InternetAccounts",
"~/Library/iTunes",
"~/Library/KeyBindings",
"~/Library/Keyboard Layouts",
"~/Library/Keychains",
"~/Library/LaunchAgents",
"~/Library/LaunchDaemons",
"~/Library/LocationBundles",
"~/Library/LoginPlugins",
"~/Library/Logs",
"~/Library/Mail",
"~/Library/Mail Downloads",
"~/Library/Messages",
"~/Library/Metadata",
"~/Library/Mobile Documents",
"~/Library/MonitorPanels",
"~/Library/OpenDirectory",
"~/Library/PDF Services",
"~/Library/PhonePlugins",
"~/Library/Phones",
"~/Library/PreferencePanes",
"~/Library/Preferences",
"~/Library/Printers",
"~/Library/PrivateFrameworks",
"~/Library/PubSub",
"~/Library/QuickLook",
"~/Library/QuickTime",
"~/Library/Receipts",
"~/Library/Recent Servers",
"~/Library/Recents",
"~/Library/Safari",
"~/Library/Saved Application State",
"~/Library/Screen Savers",
"~/Library/ScreenReader",
"~/Library/ScriptingAdditions",
"~/Library/ScriptingDefinitions",
"~/Library/Scripts",
"~/Library/Security",
"~/Library/Services",
"~/Library/Sounds",
"~/Library/Speech",
"~/Library/Spelling",
"~/Library/Spotlight",
"~/Library/StartupItems",
"~/Library/StickiesDatabase",
"~/Library/Sync Services",
"~/Library/SyncServices",
"~/Library/SyncedPreferences",
"~/Library/TextEncodings",
"~/Library/User Pictures",
"~/Library/Video",
"~/Library/Voices",
"~/Library/WebKit",
"~/Library/WidgetResources",
"~/Library/Widgets",
"~/Library/Workflows",
]
.map { |x| Pathname(x.sub(%r{^~(?=(/|$))}, Dir.home)).expand_path }
.to_set
.union(SYSTEM_DIRS)

View File

@ -1,9 +1,9 @@
module Hbc
class Pkg
def self.all_matching(regexp, command)
command.run("/usr/sbin/pkgutil", args: ["--pkgs=#{regexp}"]).stdout.split("\n").map { |package_id|
command.run("/usr/sbin/pkgutil", args: ["--pkgs=#{regexp}"]).stdout.split("\n").map do |package_id|
new(package_id.chomp, command)
}
end
end
attr_reader :package_id
@ -76,7 +76,7 @@ module Hbc
end
def _with_full_permissions(path)
original_mode = (path.stat.mode % 0o1000).to_s(8)
original_mode = (path.stat.mode % 01000).to_s(8)
# TODO: similarly read and restore macOS flags (cf man chflags)
@command.run!("/bin/chmod", args: ["--", "777", path], sudo: true)
yield

View File

@ -3,20 +3,20 @@ module Hbc
REPO_PREFIX = "homebrew-".freeze
# per https://github.com/Homebrew/homebrew/blob/4c7bc9ec3bca729c898ee347b6135ba692ee0274/Library/Homebrew/cmd/tap.rb#L121
USER_REGEX = %r{[a-z0-9_\-]+}
USER_REGEX = /[a-z0-9_\-]+/
# per https://github.com/Homebrew/homebrew/blob/4c7bc9ec3bca729c898ee347b6135ba692ee0274/Library/Homebrew/cmd/tap.rb#L121
REPO_REGEX = %r{(?:#{REPO_PREFIX})?\w+}
REPO_REGEX = /(?:#{REPO_PREFIX})?\w+/
# per https://github.com/caskroom/homebrew-cask/blob/master/CONTRIBUTING.md#generating-a-token-for-the-cask
TOKEN_REGEX = %r{[a-z0-9\-]+}
TOKEN_REGEX = /[a-z0-9\-]+/
TAP_REGEX = %r{#{USER_REGEX}[/\-]#{REPO_REGEX}}
QUALIFIED_TOKEN_REGEX = %r{#{TAP_REGEX}/#{TOKEN_REGEX}}
def self.parse(arg)
return nil unless arg.is_a?(String) && arg.downcase =~ %r{^#{QUALIFIED_TOKEN_REGEX}$}
return nil unless arg.is_a?(String) && arg.downcase =~ /^#{QUALIFIED_TOKEN_REGEX}$/
path_elements = arg.downcase.split("/")
if path_elements.count == 2
# eg phinze-cask/google-chrome.
@ -31,7 +31,7 @@ module Hbc
# per https://github.com/Homebrew/brew/blob/master/docs/brew-tap.md
user, repo, token = path_elements
end
repo.sub!(%r{^#{REPO_PREFIX}}, "")
repo.sub!(/^#{REPO_PREFIX}/, "")
odebug "[user, repo, token] might be [#{user}, #{repo}, #{token}]"
[user, repo, token]
end

View File

@ -15,11 +15,11 @@ module Hbc
end
def all_tokens
Tap.map { |t|
t.cask_files.map { |p|
Tap.map do |t|
t.cask_files.map do |p|
"#{t.name}/#{File.basename(p, ".rb")}"
}
}.flatten
end
end.flatten
end
def installed
@ -28,19 +28,19 @@ module Hbc
# TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly)
# TODO: ability to specify expected source when calling Hbc.load (minor perf benefit)
Pathname.glob(caskroom.join("*"))
.map { |caskroom_path|
.map do |caskroom_path|
token = caskroom_path.basename.to_s
path_to_cask = all_tapped_cask_dirs.find { |tap_dir|
path_to_cask = all_tapped_cask_dirs.find do |tap_dir|
tap_dir.join("#{token}.rb").exist?
}
end
if path_to_cask
Hbc.load(path_to_cask.join("#{token}.rb"))
else
Hbc.load(token)
end
}
end
end
end
end

View File

@ -22,11 +22,11 @@ module Hbc
def self.for_query(query)
odebug "Translating '#{query}' into a valid Cask source"
raise CaskUnavailableError, query if query.to_s =~ %r{^\s*$}
source = sources.find { |s|
raise CaskUnavailableError, query if query.to_s =~ /^\s*$/
source = sources.find do |s|
odebug "Testing source class #{s}"
s.me?(query)
}
end
raise CaskUnavailableError, query unless source
odebug "Success! Using source class #{source}"
resolved_cask_source = source.new(query)

View File

@ -7,7 +7,7 @@ module Hbc
# derived classes must define method self.me?
def self.path_for_query(query)
Pathname.new(query).sub(%r{(\.rb)?$}, ".rb")
Pathname.new(query).sub(/(\.rb)?$/, ".rb")
end
attr_reader :path

View File

@ -66,13 +66,13 @@ module Hbc
end
def expanded_command
@expanded_command ||= command.map { |arg|
@expanded_command ||= command.map do |arg|
if arg.respond_to?(:to_path)
File.absolute_path(arg)
else
String(arg)
end
}
end
end
def each_output_line(&b)
@ -144,7 +144,7 @@ module Hbc
end
def self._warn_plist_garbage(command, garbage)
return true unless garbage =~ %r{\S}
return true unless garbage =~ /\S/
external = File.basename(command.first)
lines = garbage.strip.split("\n")
opoo "Non-XML stdout from #{external}:"
@ -152,8 +152,8 @@ module Hbc
end
def self._parse_plist(command, output)
raise CaskError, "Empty plist input" unless output =~ %r{\S}
output.sub!(%r{\A(.*?)(<\?\s*xml)}m, '\2')
raise CaskError, "Empty plist input" unless output =~ /\S/
output.sub!(/\A(.*?)(<\?\s*xml)/m, '\2')
_warn_plist_garbage(command, Regexp.last_match[1]) if Hbc.debug
output.sub!(%r{(<\s*/\s*plist\s*>)(.*?)\Z}m, '\1')
_warn_plist_garbage(command, Regexp.last_match[2])

View File

@ -23,16 +23,16 @@ module Hbc
end
HTTP_RESPONSES = [
"HTTP/1.0 200 OK",
"HTTP/1.1 200 OK",
"HTTP/1.1 302 Found",
].freeze
"HTTP/1.0 200 OK",
"HTTP/1.1 200 OK",
"HTTP/1.1 302 Found",
].freeze
OK_RESPONSES = {
"http" => HTTP_RESPONSES,
"https" => HTTP_RESPONSES,
"ftp" => ["OK"],
}.freeze
"http" => HTTP_RESPONSES,
"https" => HTTP_RESPONSES,
"ftp" => ["OK"],
}.freeze
def _check_response_status
ok = OK_RESPONSES[cask.url.scheme]
@ -52,7 +52,7 @@ module Hbc
case cask.url.scheme
when "http", "https" then
@response_status = response_lines.grep(%r{^HTTP}).last
@response_status = response_lines.grep(/^HTTP/).last
if @response_status.respond_to?(:strip)
@response_status.strip!
unless response_lines.index(@response_status).nil?

View File

@ -12,7 +12,7 @@ class Object
def utf8_inspect
return inspect unless defined?(Encoding)
return map(&:utf8_inspect) if respond_to?(:map)
inspect.force_encoding("UTF-8").sub(%r{\A"(.*)"\Z}, '\1')
inspect.force_encoding("UTF-8").sub(/\A"(.*)"\Z/, '\1')
end
end

View File

@ -2,6 +2,6 @@ module HashValidator
def assert_valid_keys(*valid_keys)
unknown_keys = keys - valid_keys
return if unknown_keys.empty?
raise CaskError, %Q{Unknown keys: #{unknown_keys.inspect}. Running "#{UPDATE_CMD}" will likely fix it.}
raise CaskError, %Q(Unknown keys: #{unknown_keys.inspect}. Running "#{UPDATE_CMD}" will likely fix it.)
end
end

View File

@ -40,10 +40,10 @@ module Hbc
def import_key
args = if cask.gpg.key_id
["--recv-keys", cask.gpg.key_id]
elsif cask.gpg.key_url
["--fetch-key", cask.gpg.key_url.to_s]
end
["--recv-keys", cask.gpg.key_id]
elsif cask.gpg.key_url
["--fetch-key", cask.gpg.key_url.to_s]
end
@command.run!("gpg", args: args)
end

View File

@ -20,7 +20,7 @@ describe Hbc::Audit do
audit.add_error "bad"
end
it { is_expected.to match(%r{failed}) }
it { is_expected.to match(/failed/) }
end
context "when there are warnings" do
@ -28,7 +28,7 @@ describe Hbc::Audit do
audit.add_warning "eh"
end
it { is_expected.to match(%r{warning}) }
it { is_expected.to match(/warning/) }
end
context "when there are errors and warnings" do
@ -37,11 +37,11 @@ describe Hbc::Audit do
audit.add_warning "eh"
end
it { is_expected.to match(%r{failed}) }
it { is_expected.to match(/failed/) }
end
context "when there are no errors or warnings" do
it { is_expected.to match(%r{passed}) }
it { is_expected.to match(/passed/) }
end
end
@ -53,7 +53,7 @@ describe Hbc::Audit do
%w[version sha256 url name homepage].each do |stanza|
context "when missing #{stanza}" do
let(:cask_token) { "missing-#{stanza}" }
it { is_expected.to fail_with(%r{#{stanza} stanza is required}) }
it { is_expected.to fail_with(/#{stanza} stanza is required/) }
end
end
end
@ -85,36 +85,36 @@ describe Hbc::Audit do
context "when sha256 is sha256 for empty string" do
let(:cask_token) { "sha256-for-empty-string" }
it { is_expected.to fail_with(%r{cannot use the sha256 for an empty string}) }
it { is_expected.to fail_with(/cannot use the sha256 for an empty string/) }
end
end
describe "appcast checks" do
context "when appcast has no sha256" do
let(:cask_token) { "appcast-missing-checkpoint" }
it { is_expected.to fail_with(%r{checkpoint sha256 is required for appcast}) }
it { is_expected.to fail_with(/checkpoint sha256 is required for appcast/) }
end
context "when appcast checkpoint is not a string of 64 hexadecimal characters" do
let(:cask_token) { "appcast-invalid-checkpoint" }
it { is_expected.to fail_with(%r{string must be of 64 hexadecimal characters}) }
it { is_expected.to fail_with(/string must be of 64 hexadecimal characters/) }
end
context "when appcast checkpoint is sha256 for empty string" do
let(:cask_token) { "appcast-checkpoint-sha256-for-empty-string" }
it { is_expected.to fail_with(%r{cannot use the sha256 for an empty string}) }
it { is_expected.to fail_with(/cannot use the sha256 for an empty string/) }
end
context "when appcast checkpoint is valid sha256" do
let(:cask_token) { "appcast-valid-checkpoint" }
it { should_not fail_with(%r{appcast :checkpoint}) }
it { should_not fail_with(/appcast :checkpoint/) }
end
context "when verifying appcast HTTP code" do
let(:cask_token) { "appcast-valid-checkpoint" }
let(:download) { instance_double(Hbc::Download) }
let(:wrong_code_msg) { %r{unexpected HTTP response code} }
let(:curl_error_msg) { %r{error retrieving appcast} }
let(:wrong_code_msg) { /unexpected HTTP response code/ }
let(:curl_error_msg) { /error retrieving appcast/ }
let(:fake_curl_result) { instance_double(Hbc::SystemCommand::Result) }
before do
@ -155,8 +155,8 @@ describe Hbc::Audit do
context "when verifying appcast checkpoint" do
let(:cask_token) { "appcast-valid-checkpoint" }
let(:download) { instance_double(Hbc::Download) }
let(:mismatch_msg) { %r{appcast checkpoint mismatch} }
let(:curl_error_msg) { %r{error retrieving appcast} }
let(:mismatch_msg) { /appcast checkpoint mismatch/ }
let(:curl_error_msg) { /error retrieving appcast/ }
let(:fake_curl_result) { instance_double(Hbc::SystemCommand::Result) }
let(:expected_checkpoint) { "d5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2" }
@ -203,7 +203,7 @@ describe Hbc::Audit do
end
describe "preferred download URL formats" do
let(:warning_msg) { %r{URL format incorrect} }
let(:warning_msg) { /URL format incorrect/ }
context "with incorrect SourceForge URL format" do
let(:cask_token) { "sourceforge-incorrect-url-format" }
@ -234,17 +234,17 @@ describe Hbc::Audit do
describe "generic artifact checks" do
context "with no target" do
let(:cask_token) { "generic-artifact-no-target" }
it { is_expected.to fail_with(%r{target required for generic artifact}) }
it { is_expected.to fail_with(/target required for generic artifact/) }
end
context "with relative target" do
let(:cask_token) { "generic-artifact-relative-target" }
it { is_expected.to fail_with(%r{target must be absolute path for generic artifact}) }
it { is_expected.to fail_with(/target must be absolute path for generic artifact/) }
end
context "with absolute target" do
let(:cask_token) { "generic-artifact-absolute-target" }
it { should_not fail_with(%r{target required for generic artifact}) }
it { should_not fail_with(/target required for generic artifact/) }
end
end
@ -260,7 +260,7 @@ describe Hbc::Audit do
context "when doing the audit" do
it "evaluates the block" do
expect(subject).to fail_with(%r{Boom})
expect(subject).to fail_with(/Boom/)
end
end
end
@ -276,12 +276,12 @@ describe Hbc::Audit do
context "when cask token conflicts with a core formula" do
let(:formula_names) { %w[with-binary other-formula] }
it { is_expected.to warn_with(%r{possible duplicate}) }
it { is_expected.to warn_with(/possible duplicate/) }
end
context "when cask token does not conflict with a core formula" do
let(:formula_names) { %w[other-formula] }
it { should_not warn_with(%r{possible duplicate}) }
it { should_not warn_with(/possible duplicate/) }
end
end
@ -298,7 +298,7 @@ describe Hbc::Audit do
expect(verify).to receive(:all)
end
it { should_not fail_with(%r{#{error_msg}}) }
it { should_not fail_with(/#{error_msg}/) }
end
context "when download fails" do
@ -306,7 +306,7 @@ describe Hbc::Audit do
expect(download).to receive(:perform).and_raise(StandardError.new(error_msg))
end
it { is_expected.to fail_with(%r{#{error_msg}}) }
it { is_expected.to fail_with(/#{error_msg}/) }
end
context "when verification fails" do
@ -315,7 +315,7 @@ describe Hbc::Audit do
expect(verify).to receive(:all).and_raise(StandardError.new(error_msg))
end
it { is_expected.to fail_with(%r{#{error_msg}}) }
it { is_expected.to fail_with(/#{error_msg}/) }
end
end
@ -325,7 +325,7 @@ describe Hbc::Audit do
expect(cask).to receive(:version).and_raise(StandardError.new)
end
it { is_expected.to fail_with(%r{exception while auditing}) }
it { is_expected.to fail_with(/exception while auditing/) }
end
end
end

View File

@ -13,9 +13,9 @@ describe Hbc::CLI::Cleanup do
cleaned_up_cached_download = "caffeine"
cached_downloads = [
cache_location.join("#{cleaned_up_cached_download}--latest.zip"),
cache_location.join("transmission--2.61.dmg"),
]
cache_location.join("#{cleaned_up_cached_download}--latest.zip"),
cache_location.join("transmission--2.61.dmg"),
]
cached_downloads.each(&FileUtils.method(:touch))

View File

@ -4,7 +4,7 @@ describe Hbc::CLI::Doctor do
it "displays some nice info about the environment" do
expect {
Hbc::CLI::Doctor.run
}.to output(%r{\A==> macOS Release:}).to_stdout
}.to output(/\A==> macOS Release:/).to_stdout
end
it "raises an exception when arguments are given" do

View File

@ -68,9 +68,9 @@ describe "download strategies" do
let(:url_options) {
{
cookies: {
coo: "kie",
mon: "ster",
},
coo: "kie",
mon: "ster",
},
}
}
@ -114,9 +114,9 @@ describe "download strategies" do
{
using: :post,
data: {
form: "data",
is: "good",
},
form: "data",
is: "good",
},
}
}
@ -190,13 +190,13 @@ describe "download strategies" do
expect(fake_system_command).to have_received(:run!).with(
"/usr/bin/svn",
hash_including(args: [
"checkout",
"--force",
"--config-option",
"config:miscellany:use-commit-times=yes",
cask.url.to_s,
downloader.cached_location,
])
"checkout",
"--force",
"--config-option",
"config:miscellany:use-commit-times=yes",
cask.url.to_s,
downloader.cached_location,
])
)
end
@ -218,15 +218,15 @@ describe "download strategies" do
expect(fake_system_command).to have_received(:run!).with(
"/usr/bin/svn",
hash_including(args: [
"checkout",
"--force",
"--config-option",
"config:miscellany:use-commit-times=yes",
"--trust-server-cert",
"--non-interactive",
cask.url.to_s,
downloader.cached_location,
])
"checkout",
"--force",
"--config-option",
"config:miscellany:use-commit-times=yes",
"--trust-server-cert",
"--non-interactive",
cask.url.to_s,
downloader.cached_location,
])
)
end
end
@ -249,15 +249,15 @@ describe "download strategies" do
expect(fake_system_command).to have_received(:run!).with(
"/usr/bin/svn",
hash_including(args: [
"checkout",
"--force",
"--config-option",
"config:miscellany:use-commit-times=yes",
cask.url.to_s,
downloader.cached_location,
"-r",
"10",
])
"checkout",
"--force",
"--config-option",
"config:miscellany:use-commit-times=yes",
cask.url.to_s,
downloader.cached_location,
"-r",
"10",
])
)
end
end
@ -276,14 +276,14 @@ describe "download strategies" do
expect(fake_system_command).to have_received(:run!).with(
"/usr/bin/tar",
hash_including(args: [
'-s/^\\.//',
"--exclude",
".svn",
"-cf",
downloader.tarball_path,
"--",
".",
])
'-s/^\\.//',
"--exclude",
".svn",
"-cf",
downloader.tarball_path,
"--",
".",
])
)
end
end

View File

@ -1,6 +1,6 @@
describe Hbc::DSL::StanzaProxy do
let(:stanza_proxy) {
described_class.new(Array) { %i{foo bar cake} }
described_class.new(Array) { [:foo, :bar, :cake] }
}
subject { stanza_proxy }

View File

@ -49,9 +49,9 @@ describe Hbc::SystemCommand do
let(:command) { "/bin/bash" }
let(:options) {
{ args: [
"-c",
"for i in $(seq 1 2 5); do echo $i; echo $(($i + 1)) >&2; done",
] }
"-c",
"for i in $(seq 1 2 5); do echo $i; echo $(($i + 1)) >&2; done",
] }
}
shared_examples "it returns '1 2 3 4 5 6'" do
@ -84,7 +84,7 @@ describe Hbc::SystemCommand do
(1..6).each do |i|
expect {
described_class.run(command, options)
}.to output(%r{==> #{ i }}).to_stdout
}.to output(/==> #{ i }/).to_stdout
end
end
@ -125,9 +125,9 @@ describe Hbc::SystemCommand do
let(:command) { "/bin/bash" }
let(:options) {
{ args: [
"-c",
"for i in $(seq 1 2 100000); do echo $i; echo $(($i + 1)) >&2; done",
] }
"-c",
"for i in $(seq 1 2 100000); do echo $i; echo $(($i + 1)) >&2; done",
] }
}
it "returns without deadlocking" do

View File

@ -5,10 +5,10 @@ describe Formatter do
describe "::columns" do
let(:input) {
[
'aa',
'bbb',
'ccc',
'dd'
"aa",
"bbb",
"ccc",
"dd",
]
}
subject { described_class.columns(input) }

View File

@ -11,7 +11,7 @@ describe Locale do
context "raises a ParserError when given" do
it "an empty string" do
expect{ described_class.parse("") }.to raise_error(Locale::ParserError)
expect { described_class.parse("") }.to raise_error(Locale::ParserError)
end
it "a string in a wrong format" do

View File

@ -5,7 +5,7 @@ describe Hbc::Artifact::App do
let(:cask) { Hbc.load("with-alt-target") }
let(:install_phase) {
lambda { Hbc::Artifact::App.new(cask).install_phase }
-> { Hbc::Artifact::App.new(cask).install_phase }
}
let(:source_path) { cask.staged_path.join("Caffeine.app") }

View File

@ -9,13 +9,8 @@ describe Hbc::Artifact::App do
let(:source_path) { cask.staged_path.join("Caffeine.app") }
let(:target_path) { Hbc.appdir.join("Caffeine.app") }
let(:install_phase) {
lambda { app.install_phase }
}
let(:uninstall_phase) {
lambda { app.uninstall_phase }
}
let(:install_phase) { -> { app.install_phase } }
let(:uninstall_phase) { -> { app.uninstall_phase } }
before do
TestHelper.install_without_artifacts(cask)
@ -243,7 +238,7 @@ describe Hbc::Artifact::App do
describe "app is missing" do
it "returns a warning and the supposed path to the app" do
contents.size.must_equal 1
contents[0].must_match(%r{.*Missing App.*: #{target_path}})
contents[0].must_match(/.*Missing App.*: #{target_path}/)
end
end
end

View File

@ -4,7 +4,7 @@ describe Hbc::Artifact::Artifact do
let(:cask) { Hbc.load("with-generic-artifact") }
let(:install_phase) {
lambda { Hbc::Artifact::Artifact.new(cask).install_phase }
-> { Hbc::Artifact::Artifact.new(cask).install_phase }
}
let(:source_path) { cask.staged_path.join("Caffeine.app") }

View File

@ -3,9 +3,7 @@ require "test_helper"
describe Hbc::Artifact::Suite do
let(:cask) { Hbc.load("with-suite") }
let(:install_phase) {
lambda { Hbc::Artifact::Suite.new(cask).install_phase }
}
let(:install_phase) { -> { Hbc::Artifact::Suite.new(cask).install_phase } }
let(:target_path) { Hbc.appdir.join("Caffeine") }
let(:source_path) { cask.staged_path.join("Caffeine") }

View File

@ -5,7 +5,7 @@ describe Hbc::Artifact::App do
let(:cask) { Hbc.load("with-two-apps-correct") }
let(:install_phase) {
lambda { Hbc::Artifact::App.new(cask).install_phase }
-> { Hbc::Artifact::App.new(cask).install_phase }
}
let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") }

View File

@ -201,10 +201,10 @@ describe Hbc::Artifact::Uninstall do
let(:bundle_id) { "my.fancy.package.app" }
let(:count_processes_script) {
'tell application "System Events" to count processes ' +
%Q{whose bundle identifier is "#{bundle_id}"}
%Q(whose bundle identifier is "#{bundle_id}")
}
let(:quit_application_script) {
%Q{tell application id "#{bundle_id}" to quit}
%Q(tell application id "#{bundle_id}" to quit)
}
it "can uninstall" do
@ -227,7 +227,7 @@ describe Hbc::Artifact::Uninstall do
let(:unix_pids) { [12_345, 67_890] }
let(:get_unix_pids_script) {
'tell application "System Events" to get the unix id of every process ' +
%Q{whose bundle identifier is "#{bundle_id}"}
%Q(whose bundle identifier is "#{bundle_id}")
}
it "can uninstall" do

View File

@ -202,10 +202,10 @@ describe Hbc::Artifact::Zap do
let(:bundle_id) { "my.fancy.package.app" }
let(:count_processes_script) {
'tell application "System Events" to count processes ' +
%Q{whose bundle identifier is "#{bundle_id}"}
%Q(whose bundle identifier is "#{bundle_id}")
}
let(:quit_application_script) {
%Q{tell application id "#{bundle_id}" to quit}
%Q(tell application id "#{bundle_id}" to quit)
}
it "can zap" do
@ -228,7 +228,7 @@ describe Hbc::Artifact::Zap do
let(:unix_pids) { [12_345, 67_890] }
let(:get_unix_pids_script) {
'tell application "System Events" to get the unix id of every process ' +
%Q{whose bundle identifier is "#{bundle_id}"}
%Q(whose bundle identifier is "#{bundle_id}")
}
it "can zap" do

View File

@ -34,8 +34,8 @@ describe Hbc::CLI::Create do
it "opens the editor for the specified Cask" do
Hbc::CLI::Create.run("new-cask")
Hbc::CLI::Create.editor_commands.must_equal [
[Hbc.path("new-cask")],
]
[Hbc.path("new-cask")],
]
end
it "drops a template down for the specified Cask" do
@ -58,15 +58,15 @@ describe Hbc::CLI::Create do
it "throws away additional Cask arguments and uses the first" do
Hbc::CLI::Create.run("additional-cask", "another-cask")
Hbc::CLI::Create.editor_commands.must_equal [
[Hbc.path("additional-cask")],
]
[Hbc.path("additional-cask")],
]
end
it "throws away stray options" do
Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask")
Hbc::CLI::Create.editor_commands.must_equal [
[Hbc.path("yet-another-cask")],
]
[Hbc.path("yet-another-cask")],
]
end
it "raises an exception when the Cask already exists" do
@ -78,8 +78,8 @@ describe Hbc::CLI::Create do
it "allows creating Casks that are substrings of existing Casks" do
Hbc::CLI::Create.run("feine")
Hbc::CLI::Create.editor_commands.must_equal [
[Hbc.path("feine")],
]
[Hbc.path("feine")],
]
end
describe "when no Cask is specified" do

View File

@ -27,15 +27,15 @@ describe Hbc::CLI::Edit do
it "opens the editor for the specified Cask" do
Hbc::CLI::Edit.run("alfred")
Hbc::CLI::Edit.editor_commands.must_equal [
[Hbc.path("alfred")],
]
[Hbc.path("alfred")],
]
end
it "throws away additional arguments and uses the first" do
Hbc::CLI::Edit.run("adium", "alfred")
Hbc::CLI::Edit.editor_commands.must_equal [
[Hbc.path("adium")],
]
[Hbc.path("adium")],
]
end
it "raises an exception when the Cask doesnt exist" do

View File

@ -27,22 +27,22 @@ describe Hbc::CLI::Home do
it "opens the homepage for the specified Cask" do
Hbc::CLI::Home.run("alfred")
Hbc::CLI::Home.system_commands.must_equal [
["/usr/bin/open", "--", "https://www.alfredapp.com/"],
]
["/usr/bin/open", "--", "https://www.alfredapp.com/"],
]
end
it "works for multiple Casks" do
Hbc::CLI::Home.run("alfred", "adium")
Hbc::CLI::Home.system_commands.must_equal [
["/usr/bin/open", "--", "https://www.alfredapp.com/"],
["/usr/bin/open", "--", "https://www.adium.im/"],
]
["/usr/bin/open", "--", "https://www.alfredapp.com/"],
["/usr/bin/open", "--", "https://www.adium.im/"],
]
end
it "opens the project page when no Cask is specified" do
Hbc::CLI::Home.run
Hbc::CLI::Home.system_commands.must_equal [
["/usr/bin/open", "--", "http://caskroom.io/"],
]
["/usr/bin/open", "--", "http://caskroom.io/"],
]
end
end

View File

@ -29,7 +29,7 @@ describe Hbc::CLI::Install do
lambda {
Hbc::CLI::Install.run("local-transmission", "")
}.must_output nil, %r{Warning: A Cask for local-transmission is already installed.}
}.must_output nil, /Warning: A Cask for local-transmission is already installed./
end
it "allows double install with --force" do
@ -39,7 +39,7 @@ describe Hbc::CLI::Install do
lambda {
Hbc::CLI::Install.run("local-transmission", "--force")
}.must_output %r{==> Success! local-transmission was successfully installed!}
}.must_output(/==> Success! local-transmission was successfully installed!/)
end
it "skips dependencies with --skip-cask-deps" do
@ -63,16 +63,20 @@ describe Hbc::CLI::Install do
lambda {
begin
Hbc::CLI::Install.run("googlechrome")
rescue Hbc::CaskError; end
}.must_output nil, %r{No available Cask for googlechrome\. Did you mean:\ngoogle-chrome}
rescue Hbc::CaskError
nil
end
}.must_output(nil, /No available Cask for googlechrome\. Did you mean:\ngoogle-chrome/)
end
it "returns multiple suggestions for a Cask fragment" do
lambda {
begin
Hbc::CLI::Install.run("google")
rescue Hbc::CaskError; end
}.must_output nil, %r{No available Cask for google\. Did you mean one of:\ngoogle}
rescue Hbc::CaskError
nil
end
}.must_output(nil, /No available Cask for google\. Did you mean one of:\ngoogle/)
end
describe "when no Cask is specified" do

View File

@ -19,25 +19,25 @@ describe Hbc::CLI::Search do
it "lists all available Casks with no search term" do
out = capture_io { Hbc::CLI::Search.run }[0]
out.must_match(%r{google-chrome})
out.must_match(/google-chrome/)
out.length.must_be :>, 1000
end
it "ignores hyphens in search terms" do
out = capture_io { Hbc::CLI::Search.run("goo-gle-chrome") }[0]
out.must_match(%r{google-chrome})
out.must_match(/google-chrome/)
out.length.must_be :<, 100
end
it "ignores hyphens in Cask tokens" do
out = capture_io { Hbc::CLI::Search.run("googlechrome") }[0]
out.must_match(%r{google-chrome})
out.must_match(/google-chrome/)
out.length.must_be :<, 100
end
it "accepts multiple arguments" do
out = capture_io { Hbc::CLI::Search.run("google chrome") }[0]
out.must_match(%r{google-chrome})
out.must_match(/google-chrome/)
out.length.must_be :<, 100
end
@ -49,11 +49,11 @@ describe Hbc::CLI::Search do
it "Returns both exact and partial matches" do
out = capture_io { Hbc::CLI::Search.run("mnemosyne") }[0]
out.must_match(%r{^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne})
out.must_match(/^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne/)
end
it "does not search the Tap name" do
out = capture_io { Hbc::CLI::Search.run("caskroom") }[0]
out.must_match(%r{^No Cask found for "caskroom"\.\n})
out.must_match(/^No Cask found for "caskroom"\.\n/)
end
end

View File

@ -93,7 +93,7 @@ describe Hbc::CLI::Uninstall do
Hbc::CLI::Uninstall.run("versioned-cask")
end
out.must_match(%r{#{token} #{first_installed_version} is still installed.})
out.must_match(/#{token} #{first_installed_version} is still installed./)
err.must_be :empty?
end
end

View File

@ -88,8 +88,8 @@ describe Hbc::DSL do
end
cask.name.must_equal [
"Proper Name",
]
"Proper Name",
]
end
it "Accepts an array value to the name stanza" do
@ -98,9 +98,9 @@ describe Hbc::DSL do
end
cask.name.must_equal [
"Proper Name",
"Alternate Name",
]
"Proper Name",
"Alternate Name",
]
end
it "Accepts multiple name stanzas" do
@ -110,9 +110,9 @@ describe Hbc::DSL do
end
cask.name.must_equal [
"Proper Name",
"Alternate Name",
]
"Proper Name",
"Alternate Name",
]
end
end
@ -250,7 +250,7 @@ describe Hbc::DSL do
describe "appcast stanza" do
it "allows appcasts to be specified" do
cask = Hbc.load("with-appcast")
cask.appcast.to_s.must_match %r{^http}
cask.appcast.to_s.must_match(/^http/)
end
it "prevents defining multiple appcasts" do
@ -270,12 +270,12 @@ describe Hbc::DSL do
describe "gpg stanza" do
it "allows gpg stanza to be specified" do
cask = Hbc.load("with-gpg")
cask.gpg.to_s.must_match %r{\S}
cask.gpg.to_s.must_match(/\S/)
end
it "allows gpg stanza to be specified with :key_url" do
cask = Hbc.load("with-gpg-key-url")
cask.gpg.to_s.must_match %r{\S}
cask.gpg.to_s.must_match(/\S/)
end
it "prevents specifying gpg stanza multiple times" do

View File

@ -239,7 +239,7 @@ describe Hbc::Installer do
with_caveats = Hbc.load("with-caveats")
lambda {
Hbc::Installer.new(with_caveats).install
}.must_output %r{Here are some things you might want to know}
}.must_output(/Here are some things you might want to know/)
with_caveats.must_be :installed?
end
@ -247,7 +247,7 @@ describe Hbc::Installer do
with_installer_manual = Hbc.load("with-installer-manual")
lambda {
Hbc::Installer.new(with_installer_manual).install
}.must_output %r{To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join('Caffeine.app')}'}
}.must_output(/To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join('Caffeine.app')}'/)
with_installer_manual.must_be :installed?
end

View File

@ -75,7 +75,7 @@ describe Hbc::Pkg do
fake_file = fake_dir.join("ima_installed_file").tap { |path| FileUtils.touch(path) }
fake_dir.chmod(0o000)
fake_dir.chmod(0000)
pkg.stubs(:pkgutil_bom_specials).returns([])
pkg.stubs(:pkgutil_bom_files).returns([fake_file])
@ -88,7 +88,7 @@ describe Hbc::Pkg do
fake_dir.must_be :directory?
fake_file.wont_be :file?
(fake_dir.stat.mode % 0o1000).to_s(8).must_equal "0"
(fake_dir.stat.mode % 01000).to_s(8).must_equal "0"
end
end
end

View File

@ -53,10 +53,10 @@ describe Plist do
parsed.keys.must_equal ["system-entities"]
parsed["system-entities"].length.must_equal 3
parsed["system-entities"].map { |e| e["dev-entry"] }.must_equal %w[
/dev/disk3s1
/dev/disk3
/dev/disk3s2
]
/dev/disk3s1
/dev/disk3
/dev/disk3s2
]
end
it "does not choke on empty input" do