aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/utils.rb33
-rw-r--r--Library/Homebrew/utils/curl.rb4
-rw-r--r--Library/Homebrew/utils/github.rb14
-rw-r--r--Library/Homebrew/utils/hash.rb4
-rw-r--r--Library/Homebrew/utils/inreplace.rb8
-rw-r--r--Library/Homebrew/utils/shell.rb6
6 files changed, 38 insertions, 31 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 4b8aeaff4..47251a7d6 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -138,11 +138,10 @@ def odeprecated(method, replacement = nil, options = {})
backtrace = options.fetch(:caller, caller)
tap_message = nil
caller_message = backtrace.detect do |line|
- if line =~ %r{^#{Regexp.escape HOMEBREW_LIBRARY}/Taps/([^/]+/[^/]+)/}
- tap = Tap.fetch $1
- tap_message = "\nPlease report this to the #{tap} tap!"
- true
- end
+ next unless line =~ %r{^#{Regexp.escape HOMEBREW_LIBRARY}/Taps/([^/]+/[^/]+)/}
+ tap = Tap.fetch $1
+ tap_message = "\nPlease report this to the #{tap} tap!"
+ true
end
caller_message ||= backtrace.detect do |line|
!line.start_with?("#{HOMEBREW_LIBRARY_PATH}/compat/")
@@ -170,7 +169,7 @@ end
def pretty_installed(f)
if !$stdout.tty?
- "#{f}"
+ f.to_s
elsif Emoji.enabled?
"#{Tty.highlight}#{f} #{Tty.green}#{Emoji.tick}#{Tty.reset}"
else
@@ -180,7 +179,7 @@ end
def pretty_uninstalled(f)
if !$stdout.tty?
- "#{f}"
+ f.to_s
elsif Emoji.enabled?
"#{f} #{Tty.red}#{Emoji.cross}#{Tty.reset}"
else
@@ -196,7 +195,7 @@ def pretty_duration(s)
m = s / 60
s %= 60
res = "#{m} minute#{plural m}"
- return res if s == 0
+ return res if s.zero?
res << " "
end
@@ -204,7 +203,7 @@ def pretty_duration(s)
end
def plural(n, s = "s")
- (n == 1) ? "" : s
+ n == 1 ? "" : s
end
def interactive_shell(f = nil)
@@ -233,7 +232,11 @@ module Homebrew
pid = fork do
yield if block_given?
args.collect!(&:to_s)
- exec(cmd, *args) rescue nil
+ begin
+ exec(cmd, *args)
+ rescue
+ nil
+ end
exit! 1 # never gets here unless exec failed
end
Process.wait(pid)
@@ -291,7 +294,7 @@ module Homebrew
rescue Gem::SystemExitException => e
exit_code = e.exit_code
end
- odie "Failed to install/update the '#{name}' gem." if exit_code != 0
+ odie "Failed to install/update the '#{name}' gem." if exit_code.nonzero?
end
unless which executable
@@ -542,10 +545,10 @@ def disk_usage_readable(size_in_bytes)
end
# avoid trailing zero after decimal point
- if (size * 10).to_i % 10 == 0
+ if ((size * 10).to_i % 10).zero?
"#{size.to_i}#{unit}"
else
- "#{"%.1f" % size}#{unit}"
+ "#{format("%.1f", size)}#{unit}"
end
end
@@ -572,10 +575,10 @@ def truncate_text_to_approximate_size(s, max_bytes, options = {})
glue_bytes = glue.encode("BINARY")
n_front_bytes = (max_bytes_in * front_weight).floor
n_back_bytes = max_bytes_in - n_front_bytes
- if n_front_bytes == 0
+ if n_front_bytes.zero?
front = bytes[1..0]
back = bytes[-max_bytes_in..-1]
- elsif n_back_bytes == 0
+ elsif n_back_bytes.zero?
front = bytes[0..(max_bytes_in - 1)]
back = bytes[1..0]
else
diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb
index 68474c976..00c3a591c 100644
--- a/Library/Homebrew/utils/curl.rb
+++ b/Library/Homebrew/utils/curl.rb
@@ -1,7 +1,7 @@
require "pathname"
require "open3"
-def curl_args(extra_args=[])
+def curl_args(extra_args = [])
curl = Pathname.new ENV["HOMEBREW_CURL"]
curl = Pathname.new "/usr/bin/curl" unless curl.exist?
raise "#{curl} is not executable" unless curl.exist? && curl.executable?
@@ -9,7 +9,7 @@ def curl_args(extra_args=[])
flags = HOMEBREW_CURL_ARGS
flags -= ["--progress-bar"] if ARGV.verbose?
- args = ["#{curl}"] + flags + extra_args
+ args = [curl.to_s] + flags + extra_args
args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"]
args << "--silent" if !$stdout.tty? || ENV["TRAVIS"]
args
diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb
index fce89f1af..d3f304122 100644
--- a/Library/Homebrew/utils/github.rb
+++ b/Library/Homebrew/utils/github.rb
@@ -121,7 +121,7 @@ module GitHub
end
end
- def open(url, data=nil)
+ def open(url, data = nil)
# This is a no-op if the user is opting out of using the GitHub API.
return if ENV["HOMEBREW_NO_GITHUB_API"]
@@ -154,7 +154,7 @@ module GitHub
args += ["--data", "@#{data_tmpfile.path}"]
end
- args += ["--dump-header", "#{headers_tmpfile.path}"]
+ args += ["--dump-header", headers_tmpfile.path.to_s]
output, errors, status = curl_output(url.to_s, *args)
output, _, http_code = output.rpartition("\n")
@@ -203,11 +203,15 @@ module GitHub
case http_code
when "401", "403"
- raise AuthenticationFailedError.new(output)
+ raise AuthenticationFailedError, output
when "404"
raise HTTPNotFoundError, output
else
- error = Utils::JSON.load(output)["message"] rescue nil
+ error = begin
+ Utils::JSON.load(output)["message"]
+ rescue
+ nil
+ end
error ||= "curl failed! #{errors}"
raise Error, error
end
@@ -232,7 +236,7 @@ module GitHub
def build_search_qualifier_string(qualifiers)
{
:repo => "Homebrew/homebrew-core",
- :in => "title"
+ :in => "title",
}.update(qualifiers).map do |qualifier, value|
"#{qualifier}:#{value}"
end.join("+")
diff --git a/Library/Homebrew/utils/hash.rb b/Library/Homebrew/utils/hash.rb
index 63dd02c1a..2281ce311 100644
--- a/Library/Homebrew/utils/hash.rb
+++ b/Library/Homebrew/utils/hash.rb
@@ -1,6 +1,6 @@
def deep_merge_hashes(hash1, hash2)
- merger = proc do |key, v1, v2|
- if Hash === v1 && Hash === v2
+ merger = proc do |_key, v1, v2|
+ if v1.is_a?(Hash) && v2.is_a?(Hash)
v1.merge v2, &merger
else
v2
diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb
index 9978b02fe..c7557ab41 100644
--- a/Library/Homebrew/utils/inreplace.rb
+++ b/Library/Homebrew/utils/inreplace.rb
@@ -1,9 +1,9 @@
module Utils
class InreplaceError < RuntimeError
def initialize(errors)
- super errors.inject("inreplace failed\n") { |s, (path, errs)|
+ super errors.inject("inreplace failed\n") do |s, (path, errs)|
s << "#{path}:\n" << errs.map { |e| " #{e}\n" }.join
- }
+ end
end
end
@@ -24,7 +24,7 @@ module Utils
if before.nil? && after.nil?
yield s
else
- after = after.to_s if Symbol === after
+ after = after.to_s if after.is_a? Symbol
s.gsub!(before, after, audit_result)
end
@@ -33,7 +33,7 @@ module Utils
Pathname(path).atomic_write(s)
end
- raise InreplaceError.new(errors) unless errors.empty?
+ raise InreplaceError, errors unless errors.empty?
end
module_function :inreplace
end
diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb
index c1a8f95b7..7f749186f 100644
--- a/Library/Homebrew/utils/shell.rb
+++ b/Library/Homebrew/utils/shell.rb
@@ -10,7 +10,7 @@ module Utils
}.freeze
module Shell
- UNSAFE_SHELL_CHAR = /([^A-Za-z0-9_\-.,:\/@\n])/
+ UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@\n])}
# take a path and heuristically convert it
# to a shell name, return nil if there's no match
@@ -45,7 +45,7 @@ module Utils
str
end
module_function :csh_quote
-
+
def sh_quote(str)
# ruby's implementation of shell_escape
str = str.to_s
@@ -81,7 +81,7 @@ module Utils
module_function :shell_profile
def prepend_path_in_shell_profile(path)
- case preferred_shell
+ case preferred_shell
when :bash, :ksh, :sh, :zsh, nil
"echo 'export PATH=\"#{sh_quote(path)}:$PATH\"' >> #{shell_profile}"
when :csh, :tcsh