Use guard clauses.
This commit is contained in:
parent
fc3d586584
commit
84b2276fd8
@ -41,7 +41,9 @@ module Hbc
|
|||||||
ohai "Exact match"
|
ohai "Exact match"
|
||||||
puts exact_match
|
puts exact_match
|
||||||
end
|
end
|
||||||
unless partial_matches.empty?
|
|
||||||
|
return if partial_matches.empty?
|
||||||
|
|
||||||
if extract_regexp search_term
|
if extract_regexp search_term
|
||||||
ohai "Regexp matches"
|
ohai "Regexp matches"
|
||||||
else
|
else
|
||||||
@ -49,7 +51,6 @@ module Hbc
|
|||||||
end
|
end
|
||||||
puts Formatter.columns(partial_matches)
|
puts Formatter.columns(partial_matches)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.help
|
def self.help
|
||||||
"searches all known Casks"
|
"searches all known Casks"
|
||||||
|
|||||||
@ -28,7 +28,8 @@ 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
|
output = capture_output do
|
||||||
cask.caveats.each do |caveat|
|
cask.caveats.each do |caveat|
|
||||||
if caveat.respond_to?(:eval_and_print)
|
if caveat.respond_to?(:eval_and_print)
|
||||||
@ -39,12 +40,10 @@ module Hbc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless output.empty?
|
return if output.empty?
|
||||||
ohai "Caveats"
|
ohai "Caveats"
|
||||||
puts output
|
puts output
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.capture_output(&block)
|
def self.capture_output(&block)
|
||||||
old_stdout = $stdout
|
old_stdout = $stdout
|
||||||
|
|||||||
@ -137,14 +137,14 @@ 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
|
precision = 3
|
||||||
timestamp = @timenow.strftime("%Y%m%d%H%M%S")
|
timestamp = @timenow.strftime("%Y%m%d%H%M%S")
|
||||||
fraction = format("%.#{precision}f", @timenow.to_f - @timenow.to_i)[1..-1]
|
fraction = format("%.#{precision}f", @timenow.to_f - @timenow.to_i)[1..-1]
|
||||||
timestamp.concat(fraction)
|
timestamp.concat(fraction)
|
||||||
container_path.join(timestamp)
|
container_path.join(timestamp)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.size_in_bytes(files)
|
def self.size_in_bytes(files)
|
||||||
Array(files).reduce(0) { |a, e| a + (File.size?(e) || 0) }
|
Array(files).reduce(0) { |a, e| a + (File.size?(e) || 0) }
|
||||||
|
|||||||
@ -10,11 +10,10 @@ 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)
|
||||||
@disk_cleanup_size += path_size
|
@disk_cleanup_size += path_size
|
||||||
|
|||||||
@ -57,7 +57,8 @@ 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?
|
if report.empty?
|
||||||
FileUtils.touch CACHE_FILE
|
FileUtils.touch CACHE_FILE
|
||||||
else
|
else
|
||||||
@ -69,12 +70,12 @@ class Descriptions
|
|||||||
renamings.map(&:first))
|
renamings.map(&:first))
|
||||||
end
|
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|
|
formula_names.each do |name|
|
||||||
begin
|
begin
|
||||||
desc = Formulary.factory(name).desc
|
desc = Formulary.factory(name).desc
|
||||||
@ -84,16 +85,14 @@ class Descriptions
|
|||||||
end
|
end
|
||||||
save_cache if options[:save]
|
save_cache if options[:save]
|
||||||
end
|
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.
|
||||||
def self.search(regex, field = :either)
|
def self.search(regex, field = :either)
|
||||||
|
|||||||
@ -11,10 +11,9 @@ 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
|
||||||
def setup_build_environment(formula = nil)
|
def setup_build_environment(formula = nil)
|
||||||
|
|||||||
@ -27,11 +27,10 @@ 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
|
||||||
@profile = SandboxProfile.new
|
@profile = SandboxProfile.new
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user