aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Reiter2016-10-24 17:07:57 +0200
committerMarkus Reiter2016-11-13 23:00:47 +0100
commit84b2276fd866342cd84c6ada8ffc13c5c209c3cf (patch)
treedc5b52be0021022438af2df26d22be1b4d13aef5
parentfc3d586584ea8c0208ec08c4797effa8b3824b78 (diff)
downloadbrew-84b2276fd866342cd84c6ada8ffc13c5c209c3cf.tar.bz2
Use guard clauses.
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/search.rb15
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb25
-rw-r--r--Library/Homebrew/cask/lib/hbc/utils.rb14
-rw-r--r--Library/Homebrew/cleanup.rb7
-rw-r--r--Library/Homebrew/descriptions.rb45
-rw-r--r--Library/Homebrew/extend/ENV/std.rb5
-rw-r--r--Library/Homebrew/sandbox.rb7
7 files changed, 57 insertions, 61 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb
index 8e8f8fd75..3f73fcd2e 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/search.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb
@@ -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
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index 183d1f14b..57efe97e9 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -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)
diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb
index b442efd2f..88b8a88c4 100644
--- a/Library/Homebrew/cask/lib/hbc/utils.rb
+++ b/Library/Homebrew/cask/lib/hbc/utils.rb
@@ -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)
diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb
index f7db1c11f..615a7ce9e 100644
--- a/Library/Homebrew/cleanup.rb
+++ b/Library/Homebrew/cleanup.rb
@@ -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)
diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb
index cc690c050..08860f7cf 100644
--- a/Library/Homebrew/descriptions.rb
+++ b/Library/Homebrew/descriptions.rb
@@ -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.
diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb
index 27dc95d29..14f9b81b8 100644
--- a/Library/Homebrew/extend/ENV/std.rb
+++ b/Library/Homebrew/extend/ENV/std.rb
@@ -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
diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb
index 4d0709cb4..9597dafa8 100644
--- a/Library/Homebrew/sandbox.rb
+++ b/Library/Homebrew/sandbox.rb
@@ -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