diff options
| author | Markus Reiter | 2016-10-24 17:07:57 +0200 |
|---|---|---|
| committer | Markus Reiter | 2016-11-13 23:00:47 +0100 |
| commit | 84b2276fd866342cd84c6ada8ffc13c5c209c3cf (patch) | |
| tree | dc5b52be0021022438af2df26d22be1b4d13aef5 /Library/Homebrew/descriptions.rb | |
| parent | fc3d586584ea8c0208ec08c4797effa8b3824b78 (diff) | |
| download | brew-84b2276fd866342cd84c6ada8ffc13c5c209c3cf.tar.bz2 | |
Use guard clauses.
Diffstat (limited to 'Library/Homebrew/descriptions.rb')
| -rw-r--r-- | Library/Homebrew/descriptions.rb | 45 |
1 files changed, 22 insertions, 23 deletions
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. |
