Use guard clauses.

This commit is contained in:
Markus Reiter 2016-10-24 17:07:57 +02:00
parent fc3d586584
commit 84b2276fd8
7 changed files with 57 additions and 61 deletions

View File

@ -41,7 +41,9 @@ module Hbc
ohai "Exact match"
puts exact_match
end
unless partial_matches.empty?
return if partial_matches.empty?
if extract_regexp search_term
ohai "Regexp matches"
else
@ -49,7 +51,6 @@ module Hbc
end
puts Formatter.columns(partial_matches)
end
end
def self.help
"searches all known Casks"

View File

@ -28,7 +28,8 @@ module Hbc
def self.print_caveats(cask)
odebug "Printing caveats"
unless cask.caveats.empty?
return if cask.caveats.empty?
output = capture_output do
cask.caveats.each do |caveat|
if caveat.respond_to?(:eval_and_print)
@ -39,12 +40,10 @@ module Hbc
end
end
unless output.empty?
return if output.empty?
ohai "Caveats"
puts output
end
end
end
def self.capture_output(&block)
old_stdout = $stdout

View File

@ -137,14 +137,14 @@ module Hbc
def self.nowstamp_metadata_path(container_path)
@timenow ||= Time.now.gmtime
if container_path.respond_to?(:join)
return unless container_path.respond_to?(:join)
precision = 3
timestamp = @timenow.strftime("%Y%m%d%H%M%S")
fraction = format("%.#{precision}f", @timenow.to_f - @timenow.to_i)[1..-1]
timestamp.concat(fraction)
container_path.join(timestamp)
end
end
def self.size_in_bytes(files)
Array(files).reduce(0) { |a, e| a + (File.size?(e) || 0) }

View File

@ -10,11 +10,10 @@ module Homebrew
cleanup_cellar
cleanup_cache
cleanup_logs
unless ARGV.dry_run?
return if ARGV.dry_run?
cleanup_lockfiles
rm_ds_store
end
end
def self.update_disk_cleanup_size(path_size)
@disk_cleanup_size += path_size

View File

@ -57,7 +57,8 @@ class Descriptions
# If it does exist, but the Report is empty, just touch the cache file.
# Otherwise, use the report to update the cache.
def self.update_cache(report)
if CACHE_FILE.exist?
return unless CACHE_FILE.exist?
if report.empty?
FileUtils.touch CACHE_FILE
else
@ -69,12 +70,12 @@ class Descriptions
renamings.map(&:first))
end
end
end
# Given an array of formula names, add them and their descriptions to the
# cache. Save the updated cache to disk, unless explicitly told not to.
def self.cache_formulae(formula_names, options = { save: true })
if cache
return unless cache
formula_names.each do |name|
begin
desc = Formulary.factory(name).desc
@ -84,16 +85,14 @@ class Descriptions
end
save_cache if options[:save]
end
end
# Given an array of formula names, remove them and their descriptions from
# the cache. Save the updated cache to disk, unless explicitly told not to.
def self.uncache_formulae(formula_names, options = { save: true })
if cache
return unless cache
formula_names.each { |name| @cache.delete(name) }
save_cache if options[:save]
end
end
# Given a regex, find all formulae whose specified fields contain a match.
def self.search(regex, field = :either)

View File

@ -11,10 +11,9 @@ module Stdenv
DEFAULT_FLAGS = "-march=core2 -msse4".freeze
def self.extended(base)
unless ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin"
return if ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin"
base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin"
end
end
# @private
def setup_build_environment(formula = nil)

View File

@ -27,11 +27,10 @@ class Sandbox
end
def self.print_sandbox_message
unless @printed_sandbox_message
return if @printed_sandbox_message
ohai "Using the sandbox"
@printed_sandbox_message = true
end
end
def initialize
@profile = SandboxProfile.new