No if/unless-modifier on multiline blocks.

This commit is contained in:
Markus Reiter 2016-11-13 23:37:40 +01:00
parent c648518f35
commit 59e2d67721
6 changed files with 50 additions and 35 deletions

View File

@ -94,13 +94,15 @@ module Homebrew
def load_logs(dir) def load_logs(dir)
logs = {} logs = {}
dir.children.sort.each do |file| if dir.exist?
contents = file.size? ? file.read : "empty log" dir.children.sort.each do |file|
# small enough to avoid GitHub "unicorn" page-load-timeout errors contents = file.size? ? file.read : "empty log"
max_file_size = 1_000_000 # small enough to avoid GitHub "unicorn" page-load-timeout errors
contents = truncate_text_to_approximate_size(contents, max_file_size, front_weight: 0.2) max_file_size = 1_000_000
logs[file.basename.to_s] = { content: contents } contents = truncate_text_to_approximate_size(contents, max_file_size, front_weight: 0.2)
end if dir.exist? logs[file.basename.to_s] = { content: contents }
end
end
raise "No logs." if logs.empty? raise "No logs." if logs.empty?
logs logs
end end

View File

@ -98,11 +98,12 @@ module SharedEnvExtension
end end
def remove(keys, value) def remove(keys, value)
return if value.nil?
Array(keys).each do |key| Array(keys).each do |key|
next unless self[key] next unless self[key]
self[key] = self[key].sub(value, "") self[key] = self[key].sub(value, "")
delete(key) if self[key].empty? delete(key) if self[key].empty?
end if value end
end end
def cc def cc

View File

@ -1,11 +1,13 @@
module Enumerable module Enumerable
def flat_map unless method_defined?(:flat_map)
return to_enum(:flat_map) unless block_given? def flat_map
r = [] return to_enum(:flat_map) unless block_given?
each do |*args| r = []
result = yield(*args) each do |*args|
result.respond_to?(:to_ary) ? r.concat(result) : r.push(result) result = yield(*args)
result.respond_to?(:to_ary) ? r.concat(result) : r.push(result)
end
r
end end
r end
end unless method_defined?(:flat_map)
end end

View File

@ -148,13 +148,17 @@ class Pathname
open("a", *open_args) { |f| f.puts(content) } open("a", *open_args) { |f| f.puts(content) }
end end
def binwrite(contents, *open_args) unless method_defined?(:binwrite)
open("wb", *open_args) { |f| f.write(contents) } def binwrite(contents, *open_args)
end unless method_defined?(:binwrite) open("wb", *open_args) { |f| f.write(contents) }
end
end
def binread(*open_args) unless method_defined?(:binread)
open("rb", *open_args, &:read) def binread(*open_args)
end unless method_defined?(:binread) open("rb", *open_args, &:read)
end
end
# NOTE always overwrites # NOTE always overwrites
def atomic_write(content) def atomic_write(content)
@ -353,13 +357,15 @@ class Pathname
File.symlink(src.relative_path_from(dirname), self) File.symlink(src.relative_path_from(dirname), self)
end end
def /(other) unless method_defined?(:/)
unless other.respond_to?(:to_str) || other.respond_to?(:to_path) def /(other)
opoo "Pathname#/ called on #{inspect} with #{other.inspect} as an argument" unless other.respond_to?(:to_str) || other.respond_to?(:to_path)
puts "This behavior is deprecated, please pass either a String or a Pathname" opoo "Pathname#/ called on #{inspect} with #{other.inspect} as an argument"
puts "This behavior is deprecated, please pass either a String or a Pathname"
end
self + other.to_s
end end
self + other.to_s end
end unless method_defined?(:/)
# @private # @private
def ensure_writable def ensure_writable

View File

@ -814,9 +814,11 @@ class FormulaInstaller
def lock def lock
return unless (@@locked ||= []).empty? return unless (@@locked ||= []).empty?
formula.recursive_dependencies.each do |dep| unless ignore_deps?
@@locked << dep.to_formula formula.recursive_dependencies.each do |dep|
end unless ignore_deps? @@locked << dep.to_formula
end
end
@@locked.unshift(formula) @@locked.unshift(formula)
@@locked.uniq! @@locked.uniq!
@@locked.each(&:lock) @@locked.each(&:lock)

View File

@ -6,8 +6,10 @@ class HardwareTests < Homebrew::TestCase
assert_includes [:intel, :ppc, :dunno], Hardware::CPU.type assert_includes [:intel, :ppc, :dunno], Hardware::CPU.type
end end
def test_hardware_intel_family if Hardware::CPU.intel?
families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :dunno] def test_hardware_intel_family
assert_includes families, Hardware::CPU.family families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :dunno]
end if Hardware::CPU.intel? assert_includes families, Hardware::CPU.family
end
end
end end