Run rubocop —auto-correct.

This commit is contained in:
Markus Reiter 2016-09-20 15:11:33 +02:00
parent b957a1b7e6
commit 59212445da
29 changed files with 158 additions and 134 deletions

View File

@ -31,9 +31,6 @@ Metrics/ModuleLength:
Metrics/PerceivedComplexity:
Enabled: false
Performance/StringReplacement:
Enabled: false
Style/AlignHash:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
@ -129,6 +126,8 @@ Style/RegexpLiteral:
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: comma

View File

@ -10,7 +10,7 @@ class Hbc::Artifact::AbstractFlightBlock < Hbc::Artifact::Base
end
def self.class_for_dsl_key(dsl_key)
Object.const_get("Hbc::DSL::#{dsl_key.to_s.split('_').collect(&:capitalize).join}")
Object.const_get("Hbc::DSL::#{dsl_key.to_s.split("_").collect(&:capitalize).join}")
end
def self.me?(cask)

View File

@ -64,9 +64,9 @@ class Hbc::Artifact::Moved < Hbc::Artifact::Relocated
def delete
ohai "Removing #{self.class.artifact_english_name}: '#{target}'"
if MacOS.undeletable?(target)
raise Hbc::CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}"
elsif force
raise Hbc::CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}" if MacOS.undeletable?(target)
if force
Hbc::Utils.gain_permissions_remove(target, command: @command)
else
target.rmtree

View File

@ -3,14 +3,15 @@ module Hbc::Cache
def ensure_cache_exists
return if Hbc.cache.exist?
odebug "Creating Cache at #{Hbc.cache}"
Hbc.cache.mkpath
end
def migrate_legacy_cache
if Hbc.legacy_cache.exist?
ohai "Migrating cached files to #{Hbc.cache}..."
return unless Hbc.legacy_cache.exist?
ohai "Migrating cached files to #{Hbc.cache}..."
Hbc.legacy_cache.children.select(&:symlink?).each do |symlink|
file = symlink.readlink
@ -30,5 +31,4 @@ module Hbc::Cache
FileUtils.remove_entry_secure(Hbc.legacy_cache)
end
end
end

View File

@ -87,7 +87,9 @@ class Hbc::Cask
end
def dumpcask
if Hbc.respond_to?(:debug) && Hbc.debug
return unless Hbc.respond_to?(:debug)
return unless Hbc.debug
odebug "Cask instance dumps in YAML:"
odebug "Cask instance toplevel:", to_yaml
[
@ -110,5 +112,4 @@ class Hbc::Cask
odebug "Cask instance method '#{method}':", send(method).to_yaml
end
end
end
end

View File

@ -3,7 +3,9 @@ module Hbc::Caskroom
def migrate_caskroom_from_repo_to_prefix
repo_caskroom = Hbc.homebrew_repository.join("Caskroom")
if !Hbc.caskroom.exist? && repo_caskroom.directory?
return if Hbc.caskroom.exist?
return unless repo_caskroom.directory?
ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX"
if Hbc.caskroom.parent.writable?
@ -13,12 +15,11 @@ module Hbc::Caskroom
system "/usr/bin/sudo", "--", "/bin/mv", "--", repo_caskroom.to_s, Hbc.caskroom.parent.to_s
end
end
end
def ensure_caskroom_exists
unless Hbc.caskroom.exist?
ohai "Creating Caskroom at #{Hbc.caskroom}"
return if Hbc.caskroom.exist?
ohai "Creating Caskroom at #{Hbc.caskroom}"
if Hbc.caskroom.parent.writable?
Hbc.caskroom.mkpath
else
@ -38,5 +39,4 @@ module Hbc::Caskroom
end
end
end
end
end

View File

@ -117,11 +117,11 @@ class Hbc::CLI
rescue NameError
nil
end
if klass.respond_to?(:run)
# invoke "run" on a Ruby library which follows our coding conventions
klass.run(*rest)
else
# other Ruby libraries must do everything via "require"
klass.run(*rest)
end
elsif Hbc::Utils.which "brewcask-#{command}"
# arbitrary external executable on PATH, Homebrew-style

View File

@ -6,7 +6,7 @@ class Hbc::CLI::Audit < Hbc::CLI::Base
def self.run(*args)
failed_casks = new(args, Hbc::Auditor).run
return if failed_casks.empty?
raise Hbc::CaskError, "audit failed for casks: #{failed_casks.join(' ')}"
raise Hbc::CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
end
def initialize(args, auditor)

View File

@ -65,7 +65,7 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
def remove_cache_files(*tokens)
message = "Removing cached downloads"
message.concat " for #{tokens.join(', ')}" unless tokens.empty?
message.concat " for #{tokens.join(", ")}" unless tokens.empty?
message.concat " older than #{OUTDATED_DAYS} days old" if outdated_only
ohai message

View File

@ -54,7 +54,7 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
if homebrew_origin !~ %r{\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'}"
homebrew_origin.concat " #{error_string "warning: nonstandard origin"}"
end
rescue StandardError
homebrew_origin = error_string "Not Found - Error running git"
@ -106,7 +106,7 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
end
def self.privileged_uid
Process.euid == 0 ? "Yes #{error_string 'warning: not recommended'}" : "No"
Process.euid.zero? ? "Yes #{error_string "warning: not recommended"}" : "No"
rescue StandardError
notfound_string
end
@ -143,7 +143,7 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
if dir.nil? || dir.to_s.empty?
none_string
elsif dir.to_s.match(legacy_tap_pattern)
dir.to_s.concat(" #{error_string 'Warning: legacy tap path'}")
dir.to_s.concat(" #{error_string "Warning: legacy tap path"}")
else
dir.to_s
end
@ -175,9 +175,9 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
def self.render_staging_location(path)
path = Pathname.new(path)
if !path.exist?
"#{path} #{error_string 'error: path does not exist'}}"
"#{path} #{error_string "error: path does not exist"}}"
elsif !path.writable?
"#{path} #{error_string 'error: not writable by current user'}"
"#{path} #{error_string "error: not writable by current user"}"
else
path
end

View File

@ -36,7 +36,7 @@ class Hbc::CLI::Install < Hbc::CLI::Base
count += 1
end
end
count == 0 ? nil : count == cask_tokens.length
count.zero? ? nil : count == cask_tokens.length
end
def self.warn_unavailable_with_suggestion(cask_token, e)

View File

@ -62,7 +62,7 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
end
def git_root
@git_root ||= git(*%w[rev-parse --show-toplevel])
@git_root ||= git("rev-parse", "--show-toplevel")
end
def modified_cask_files
@ -83,8 +83,8 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
@modified_casks = modified_cask_files.map { |f| Hbc.load(f) }
if @modified_casks.any?
num_modified = @modified_casks.size
ohai "#{num_modified} modified #{pluralize('cask', num_modified)}: " \
"#{@modified_casks.join(' ')}"
ohai "#{num_modified} modified #{pluralize("cask", num_modified)}: " \
"#{@modified_casks.join(" ")}"
end
@modified_casks
end
@ -122,7 +122,7 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
num_failed = failed_casks.size
cask_pluralized = pluralize("cask", num_failed)
odie "audit failed for #{num_failed} #{cask_pluralized}: " \
"#{failed_casks.join(' ')}"
"#{failed_casks.join(" ")}"
end
def pluralize(str, num)

View File

@ -21,7 +21,7 @@ class Hbc::CLI::InternalDump < Hbc::CLI::InternalUseBase
opoo "#{cask_token} was not found or would not load: #{e}"
end
end
count == 0 ? nil : count == cask_tokens.length
count.zero? ? nil : count == cask_tokens.length
end
def self.help

View File

@ -118,7 +118,7 @@ class Hbc::CLI::InternalStanza < Hbc::CLI::InternalUseBase
count += 1
end
count == 0 ? nil : count == cask_tokens.length
count.zero? ? nil : count == cask_tokens.length
end
def self.help

View File

@ -48,7 +48,7 @@ class Hbc::CLI::List < Hbc::CLI::Base
end
end
count == 0 ? nil : count == cask_tokens.length
count.zero? ? nil : count == cask_tokens.length
end
def self.list_artifacts(cask)

View File

@ -28,8 +28,8 @@ class Hbc::CLI::Uninstall < Hbc::CLI::Base
single = versions.count == 1
puts <<-EOS.undent
#{cask_token} #{versions.join(', ')} #{single ? 'is' : 'are'} still installed.
Remove #{single ? 'it' : 'them all'} with `brew cask uninstall --force #{cask_token}`.
#{cask_token} #{versions.join(", ")} #{single ? "is" : "are"} still installed.
Remove #{single ? "it" : "them all"} with `brew cask uninstall --force #{cask_token}`.
EOS
end
end

View File

@ -269,8 +269,16 @@ class Hbc::DSL
end
def method_missing(method, *)
if method
Hbc::Utils.method_missing_message(method, token)
nil
else
super
end
end
def respond_to_missing?(*)
true
end
def appdir

View File

@ -13,9 +13,17 @@ class Hbc::DSL::Base
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 respond_to_missing?(*)
true
end
end

View File

@ -25,13 +25,21 @@ class Hbc::DSL::StanzaProxy
coder["resolved"] = @resolver.call
end
def respond_to?(symbol, include_private = false)
return true if %i{encode_with proxy? to_s type}.include?(symbol)
return false if symbol == :to_ary
@resolver.call.respond_to?(symbol, include_private)
def method_missing(method, *args)
if method != :to_ary
@resolver.call.send(method, *args)
else
super
end
end
def method_missing(symbol, *args)
@resolver.call.send(symbol, *args)
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

View File

@ -139,7 +139,8 @@ class Hbc::Installer
# dependencies should also apply for "brew cask stage"
# override dependencies with --force or perhaps --force-deps
def satisfy_dependencies
if @cask.depends_on
return unless @cask.depends_on
ohai "Satisfying dependencies"
macos_dependencies
arch_dependencies
@ -148,7 +149,6 @@ class Hbc::Installer
cask_dependencies unless skip_cask_deps
puts "complete"
end
end
def macos_dependencies
return unless @cask.depends_on.macos
@ -159,7 +159,7 @@ class Hbc::Installer
end
elsif @cask.depends_on.macos.length > 1
unless @cask.depends_on.macos.include?(Gem::Version.new(MacOS.version.to_s))
raise Hbc::CaskError, "Cask #{@cask} depends on macOS release being one of [#{@cask.depends_on.macos.map(&:to_s).join(', ')}], but you are running release #{MacOS.version}."
raise Hbc::CaskError, "Cask #{@cask} depends on macOS release being one of [#{@cask.depends_on.macos.map(&:to_s).join(", ")}], but you are running release #{MacOS.version}."
end
else
unless MacOS.version == @cask.depends_on.macos.first
@ -175,7 +175,7 @@ class Hbc::Installer
arch[:type] == @current_arch[:type] &&
Array(arch[:bits]).include?(@current_arch[:bits])
}
raise Hbc::CaskError, "Cask #{@cask} depends on hardware architecture being one of [#{@cask.depends_on.arch.map(&:to_s).join(', ')}], but you are running #{@current_arch}"
raise Hbc::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
def x11_dependencies
@ -203,7 +203,7 @@ class Hbc::Installer
def cask_dependencies
return unless @cask.depends_on.cask && !@cask.depends_on.cask.empty?
ohai "Installing Cask dependencies: #{@cask.depends_on.cask.join(', ')}"
ohai "Installing Cask dependencies: #{@cask.depends_on.cask.join(", ")}"
deps = Hbc::CaskDependencies.new(@cask)
deps.sorted.each do |dep_token|
puts "#{dep_token} ..."

View File

@ -11,7 +11,7 @@ class Hbc::Source::TappedQualified < Hbc::Source::Tapped
qualified_token = Hbc::QualifiedToken.parse(query)
return if qualified_token.nil?
user, repo, token = qualified_token
user, repo = qualified_token[0..1]
Tap.fetch(user, repo)
end

View File

@ -123,7 +123,7 @@ class Hbc::SystemCommand::Result
end
def success?
@exit_status == 0
@exit_status.zero?
end
def merged_output

View File

@ -36,7 +36,7 @@ class Hbc::UrlChecker
def _check_response_status
ok = OK_RESPONSES[cask.url.scheme]
return if ok.include?(@response_status)
add_error "unexpected http response, expecting #{ok.map(&:utf8_inspect).join(' or ')}, got #{@response_status.utf8_inspect}"
add_error "unexpected http response, expecting #{ok.map(&:utf8_inspect).join(" or ")}, got #{@response_status.utf8_inspect}"
end
def _get_data_from_request

View File

@ -32,14 +32,15 @@ end
# global methods
def odebug(title, *sput)
if Hbc.respond_to?(:debug) && Hbc.debug
return unless Hbc.respond_to?(:debug)
return unless Hbc.debug
width = Tty.width * 4 - 6
if $stdout.tty? && title.to_s.length > width
title = title.to_s[0, width - 3] + "..."
end
puts "#{Tty.magenta}==>#{Tty.reset} #{Tty.white}#{title}#{Tty.reset}"
puts sput unless sput.empty?
end
end
module Hbc::Utils

View File

@ -12,7 +12,7 @@ describe Hbc::CLI::Cleanup do
describe "cleanup" do
it "removes cached downloads of given casks" do
cleaned_up_cached_download = 'caffeine'
cleaned_up_cached_download = "caffeine"
cached_downloads = [
cache_location.join("#{cleaned_up_cached_download}--latest.zip"),

View File

@ -9,7 +9,7 @@ end
project_root = Pathname.new(File.expand_path("../..", __FILE__))
# add Homebrew to load path
$LOAD_PATH.unshift(File.expand_path("#{ENV['HOMEBREW_REPOSITORY']}/Library/Homebrew"))
$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew"))
require "global"

View File

@ -60,7 +60,6 @@ describe Hbc::Artifact::App do
File.exist?(cask.staged_path.join("Caffeine Deluxe.app")).must_equal true
end
describe "avoids clobbering an existing app" do
let(:cask) { local_two_apps_caffeine }
@ -70,8 +69,8 @@ describe Hbc::Artifact::App do
TestHelper.must_output(self, lambda {
Hbc::Artifact::App.new(cask).install_phase
}, <<-EOS.undent.chomp)
==> It seems there is already an App at '#{Hbc.appdir.join('Caffeine Mini.app')}'; not moving.
==> Moving App 'Caffeine Pro.app' to '#{Hbc.appdir.join('Caffeine Pro.app')}'
==> It seems there is already an App at '#{Hbc.appdir.join("Caffeine Mini.app")}'; not moving.
==> Moving App 'Caffeine Pro.app' to '#{Hbc.appdir.join("Caffeine Pro.app")}'
EOS
source_path = cask.staged_path.join("Caffeine Mini.app")
@ -85,8 +84,8 @@ describe Hbc::Artifact::App do
TestHelper.must_output(self, lambda {
Hbc::Artifact::App.new(cask).install_phase
}, <<-EOS.undent.chomp)
==> Moving App 'Caffeine Mini.app' to '#{Hbc.appdir.join('Caffeine Mini.app')}'
==> It seems there is already an App at '#{Hbc.appdir.join('Caffeine Pro.app')}'; not moving.
==> Moving App 'Caffeine Mini.app' to '#{Hbc.appdir.join("Caffeine Mini.app")}'
==> It seems there is already an App at '#{Hbc.appdir.join("Caffeine Pro.app")}'; not moving.
EOS
source_path = cask.staged_path.join("Caffeine Pro.app")

View File

@ -79,9 +79,9 @@ describe Hbc::CLI::List do
Hbc::CLI::List.run("local-transmission", "local-caffeine")
}.must_output <<-EOS.undent
==> Apps
#{Hbc.appdir.join('Transmission.app')} (#{Hbc.appdir.join('Transmission.app').abv})
#{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv})
==> Apps
Missing App: #{Hbc.appdir.join('Caffeine.app')}
Missing App: #{Hbc.appdir.join("Caffeine.app")}
EOS
end
end

View File

@ -10,7 +10,7 @@ project_root = Pathname.new(File.expand_path("../..", __FILE__))
tap_root = Pathname.new(ENV["HOMEBREW_LIBRARY"]).join("Taps", "caskroom", "homebrew-cask")
# add Homebrew to load path
$LOAD_PATH.unshift(File.expand_path("#{ENV['HOMEBREW_REPOSITORY']}/Library/Homebrew"))
$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew"))
require "global"