Skip to content
Snippets Groups Projects
Commit 84b2276f authored by Markus Reiter's avatar Markus Reiter
Browse files

Use guard clauses.

parent fc3d5865
No related branches found
No related tags found
No related merge requests found
......@@ -41,14 +41,15 @@ module Hbc
ohai "Exact match"
puts exact_match
end
unless partial_matches.empty?
if extract_regexp search_term
ohai "Regexp matches"
else
ohai "Partial matches"
end
puts Formatter.columns(partial_matches)
return if partial_matches.empty?
if extract_regexp search_term
ohai "Regexp matches"
else
ohai "Partial matches"
end
puts Formatter.columns(partial_matches)
end
def self.help
......
......@@ -28,22 +28,21 @@ module Hbc
def self.print_caveats(cask)
odebug "Printing caveats"
unless cask.caveats.empty?
output = capture_output do
cask.caveats.each do |caveat|
if caveat.respond_to?(:eval_and_print)
caveat.eval_and_print(cask)
else
puts caveat
end
return if cask.caveats.empty?
output = capture_output do
cask.caveats.each do |caveat|
if caveat.respond_to?(:eval_and_print)
caveat.eval_and_print(cask)
else
puts caveat
end
end
unless output.empty?
ohai "Caveats"
puts output
end
end
return if output.empty?
ohai "Caveats"
puts output
end
def self.capture_output(&block)
......
......@@ -137,13 +137,13 @@ module Hbc
def self.nowstamp_metadata_path(container_path)
@timenow ||= Time.now.gmtime
if 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
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
def self.size_in_bytes(files)
......
......@@ -10,10 +10,9 @@ module Homebrew
cleanup_cellar
cleanup_cache
cleanup_logs
unless ARGV.dry_run?
cleanup_lockfiles
rm_ds_store
end
return if ARGV.dry_run?
cleanup_lockfiles
rm_ds_store
end
def self.update_disk_cleanup_size(path_size)
......
......@@ -57,42 +57,41 @@ 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?
if report.empty?
FileUtils.touch CACHE_FILE
else
renamings = report.select_formula(:R)
alterations = report.select_formula(:A) + report.select_formula(:M) +
renamings.map(&:last)
cache_formulae(alterations, save: false)
uncache_formulae(report.select_formula(:D) +
renamings.map(&:first))
end
return unless CACHE_FILE.exist?
if report.empty?
FileUtils.touch CACHE_FILE
else
renamings = report.select_formula(:R)
alterations = report.select_formula(:A) + report.select_formula(:M) +
renamings.map(&:last)
cache_formulae(alterations, save: false)
uncache_formulae(report.select_formula(:D) +
renamings.map(&:first))
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
formula_names.each do |name|
begin
desc = Formulary.factory(name).desc
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
end
@cache[name] = desc
return unless cache
formula_names.each do |name|
begin
desc = Formulary.factory(name).desc
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
end
save_cache if options[:save]
@cache[name] = desc
end
save_cache if options[:save]
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
formula_names.each { |name| @cache.delete(name) }
save_cache if options[:save]
end
return unless cache
formula_names.each { |name| @cache.delete(name) }
save_cache if options[:save]
end
# Given a regex, find all formulae whose specified fields contain a match.
......
......@@ -11,9 +11,8 @@ module Stdenv
DEFAULT_FLAGS = "-march=core2 -msse4".freeze
def self.extended(base)
unless ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin"
base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin"
end
return if ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin"
base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin"
end
# @private
......
......@@ -27,10 +27,9 @@ class Sandbox
end
def self.print_sandbox_message
unless @printed_sandbox_message
ohai "Using the sandbox"
@printed_sandbox_message = true
end
return if @printed_sandbox_message
ohai "Using the sandbox"
@printed_sandbox_message = true
end
def initialize
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment