diff options
| author | Mike McQuaid | 2016-09-11 17:47:04 +0100 |
|---|---|---|
| committer | Mike McQuaid | 2016-09-11 19:12:59 +0100 |
| commit | 56b6c43686be4710af7ddfeee06d456abc3aa0cf (patch) | |
| tree | 506a758b8a2bffe5578c019d3abbbc0422a367b4 /Library/Homebrew/utils.rb | |
| parent | 8448fe17cba78e35a260d4c4e0189abe7ab75fcf (diff) | |
| download | brew-56b6c43686be4710af7ddfeee06d456abc3aa0cf.tar.bz2 | |
utils: fix Rubocop warnings.
Diffstat (limited to 'Library/Homebrew/utils.rb')
| -rw-r--r-- | Library/Homebrew/utils.rb | 33 |
1 files changed, 18 insertions, 15 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 |
