Use guard clauses.
This commit is contained in:
parent
fc3d586584
commit
84b2276fd8
@ -41,14 +41,15 @@ module Hbc
|
|||||||
ohai "Exact match"
|
ohai "Exact match"
|
||||||
puts exact_match
|
puts exact_match
|
||||||
end
|
end
|
||||||
unless partial_matches.empty?
|
|
||||||
if extract_regexp search_term
|
return if partial_matches.empty?
|
||||||
ohai "Regexp matches"
|
|
||||||
else
|
if extract_regexp search_term
|
||||||
ohai "Partial matches"
|
ohai "Regexp matches"
|
||||||
end
|
else
|
||||||
puts Formatter.columns(partial_matches)
|
ohai "Partial matches"
|
||||||
end
|
end
|
||||||
|
puts Formatter.columns(partial_matches)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.help
|
def self.help
|
||||||
|
|||||||
@ -28,22 +28,21 @@ module Hbc
|
|||||||
|
|
||||||
def self.print_caveats(cask)
|
def self.print_caveats(cask)
|
||||||
odebug "Printing caveats"
|
odebug "Printing caveats"
|
||||||
unless cask.caveats.empty?
|
return if cask.caveats.empty?
|
||||||
output = capture_output do
|
|
||||||
cask.caveats.each do |caveat|
|
output = capture_output do
|
||||||
if caveat.respond_to?(:eval_and_print)
|
cask.caveats.each do |caveat|
|
||||||
caveat.eval_and_print(cask)
|
if caveat.respond_to?(:eval_and_print)
|
||||||
else
|
caveat.eval_and_print(cask)
|
||||||
puts caveat
|
else
|
||||||
end
|
puts caveat
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless output.empty?
|
|
||||||
ohai "Caveats"
|
|
||||||
puts output
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return if output.empty?
|
||||||
|
ohai "Caveats"
|
||||||
|
puts output
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.capture_output(&block)
|
def self.capture_output(&block)
|
||||||
|
|||||||
@ -137,13 +137,13 @@ module Hbc
|
|||||||
|
|
||||||
def self.nowstamp_metadata_path(container_path)
|
def self.nowstamp_metadata_path(container_path)
|
||||||
@timenow ||= Time.now.gmtime
|
@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")
|
precision = 3
|
||||||
fraction = format("%.#{precision}f", @timenow.to_f - @timenow.to_i)[1..-1]
|
timestamp = @timenow.strftime("%Y%m%d%H%M%S")
|
||||||
timestamp.concat(fraction)
|
fraction = format("%.#{precision}f", @timenow.to_f - @timenow.to_i)[1..-1]
|
||||||
container_path.join(timestamp)
|
timestamp.concat(fraction)
|
||||||
end
|
container_path.join(timestamp)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.size_in_bytes(files)
|
def self.size_in_bytes(files)
|
||||||
|
|||||||
@ -10,10 +10,9 @@ module Homebrew
|
|||||||
cleanup_cellar
|
cleanup_cellar
|
||||||
cleanup_cache
|
cleanup_cache
|
||||||
cleanup_logs
|
cleanup_logs
|
||||||
unless ARGV.dry_run?
|
return if ARGV.dry_run?
|
||||||
cleanup_lockfiles
|
cleanup_lockfiles
|
||||||
rm_ds_store
|
rm_ds_store
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_disk_cleanup_size(path_size)
|
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.
|
# If it does exist, but the Report is empty, just touch the cache file.
|
||||||
# Otherwise, use the report to update the cache.
|
# Otherwise, use the report to update the cache.
|
||||||
def self.update_cache(report)
|
def self.update_cache(report)
|
||||||
if CACHE_FILE.exist?
|
return unless CACHE_FILE.exist?
|
||||||
if report.empty?
|
|
||||||
FileUtils.touch CACHE_FILE
|
if report.empty?
|
||||||
else
|
FileUtils.touch CACHE_FILE
|
||||||
renamings = report.select_formula(:R)
|
else
|
||||||
alterations = report.select_formula(:A) + report.select_formula(:M) +
|
renamings = report.select_formula(:R)
|
||||||
renamings.map(&:last)
|
alterations = report.select_formula(:A) + report.select_formula(:M) +
|
||||||
cache_formulae(alterations, save: false)
|
renamings.map(&:last)
|
||||||
uncache_formulae(report.select_formula(:D) +
|
cache_formulae(alterations, save: false)
|
||||||
renamings.map(&:first))
|
uncache_formulae(report.select_formula(:D) +
|
||||||
end
|
renamings.map(&:first))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Given an array of formula names, add them and their descriptions to the
|
# 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.
|
# cache. Save the updated cache to disk, unless explicitly told not to.
|
||||||
def self.cache_formulae(formula_names, options = { save: true })
|
def self.cache_formulae(formula_names, options = { save: true })
|
||||||
if cache
|
return unless cache
|
||||||
formula_names.each do |name|
|
|
||||||
begin
|
formula_names.each do |name|
|
||||||
desc = Formulary.factory(name).desc
|
begin
|
||||||
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
|
desc = Formulary.factory(name).desc
|
||||||
end
|
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
|
||||||
@cache[name] = desc
|
|
||||||
end
|
end
|
||||||
save_cache if options[:save]
|
@cache[name] = desc
|
||||||
end
|
end
|
||||||
|
save_cache if options[:save]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Given an array of formula names, remove them and their descriptions from
|
# 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.
|
# the cache. Save the updated cache to disk, unless explicitly told not to.
|
||||||
def self.uncache_formulae(formula_names, options = { save: true })
|
def self.uncache_formulae(formula_names, options = { save: true })
|
||||||
if cache
|
return unless cache
|
||||||
formula_names.each { |name| @cache.delete(name) }
|
formula_names.each { |name| @cache.delete(name) }
|
||||||
save_cache if options[:save]
|
save_cache if options[:save]
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Given a regex, find all formulae whose specified fields contain a match.
|
# Given a regex, find all formulae whose specified fields contain a match.
|
||||||
|
|||||||
@ -11,9 +11,8 @@ module Stdenv
|
|||||||
DEFAULT_FLAGS = "-march=core2 -msse4".freeze
|
DEFAULT_FLAGS = "-march=core2 -msse4".freeze
|
||||||
|
|
||||||
def self.extended(base)
|
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"
|
base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
|
|||||||
@ -27,10 +27,9 @@ class Sandbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.print_sandbox_message
|
def self.print_sandbox_message
|
||||||
unless @printed_sandbox_message
|
return if @printed_sandbox_message
|
||||||
ohai "Using the sandbox"
|
ohai "Using the sandbox"
|
||||||
@printed_sandbox_message = true
|
@printed_sandbox_message = true
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user