Replace #chuzzle with ActiveSupport’s #presence.

This commit is contained in:
Markus Reiter 2018-09-17 22:02:00 +02:00
parent 16618d0fc7
commit 5dd571adeb
7 changed files with 25 additions and 21 deletions

View File

@ -18,17 +18,17 @@ module Homebrew
case ARGV.named.first
when nil, "state"
analyticsdisabled = \
Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsdisabled").chuzzle
uuid = \
Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsuuid").chuzzle
analyticsdisabled =
Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsdisabled").chomp
uuid =
Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsuuid").chomp
if ENV["HOMEBREW_NO_ANALYTICS"]
puts "Analytics is disabled (by HOMEBREW_NO_ANALYTICS)."
elsif analyticsdisabled == "true"
puts "Analytics is disabled."
else
puts "Analytics is enabled."
puts "UUID: #{uuid}" if uuid
puts "UUID: #{uuid}" if uuid.present?
end
when "on"
safe_system "git", "config", "--file=#{config_file}",

View File

@ -22,14 +22,14 @@ module Homebrew
def update_report
HOMEBREW_REPOSITORY.cd do
analytics_message_displayed =
Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsmessage").chuzzle
Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsmessage").chomp == "true"
cask_analytics_message_displayed =
Utils.popen_read("git", "config", "--local", "--get", "homebrew.caskanalyticsmessage").chuzzle
Utils.popen_read("git", "config", "--local", "--get", "homebrew.caskanalyticsmessage").chomp == "true"
analytics_disabled =
Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsdisabled").chuzzle
if analytics_message_displayed != "true" &&
cask_analytics_message_displayed != "true" &&
analytics_disabled != "true" &&
Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsdisabled").chomp == "true"
if !analytics_message_displayed &&
!cask_analytics_message_displayed &&
!analytics_disabled &&
!ENV["HOMEBREW_NO_ANALYTICS"] &&
!ENV["HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT"]
@ -53,8 +53,8 @@ module Homebrew
end
donation_message_displayed =
Utils.popen_read("git", "config", "--local", "--get", "homebrew.donationmessage").chuzzle
if donation_message_displayed != "true"
Utils.popen_read("git", "config", "--local", "--get", "homebrew.donationmessage").chomp == "true"
unless donation_message_displayed
ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"
puts " #{Formatter.url("https://github.com/Homebrew/brew#donations")}\n"

View File

@ -9,7 +9,7 @@ module GitRepositoryExtension
def git_origin
return unless git? && Utils.git_available?
Utils.popen_read("git", "config", "--get", "remote.origin.url", chdir: self).chuzzle
Utils.popen_read("git", "config", "--get", "remote.origin.url", chdir: self).chomp.presence
end
def git_origin=(origin)
@ -21,30 +21,30 @@ module GitRepositoryExtension
def git_head
return unless git? && Utils.git_available?
Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD", chdir: self).chuzzle
Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD", chdir: self).chomp.presence
end
def git_short_head
return unless git? && Utils.git_available?
Utils.popen_read("git", "rev-parse", "--short=4", "--verify", "-q", "HEAD", chdir: self).chuzzle
Utils.popen_read("git", "rev-parse", "--short=4", "--verify", "-q", "HEAD", chdir: self).chomp.presence
end
def git_last_commit
return unless git? && Utils.git_available?
Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD", chdir: self).chuzzle
Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD", chdir: self).chomp.presence
end
def git_branch
return unless git? && Utils.git_available?
Utils.popen_read("git", "rev-parse", "--abbrev-ref", "HEAD", chdir: self).chuzzle
Utils.popen_read("git", "rev-parse", "--abbrev-ref", "HEAD", chdir: self).chomp.presence
end
def git_last_commit_date
return unless git? && Utils.git_available?
Utils.popen_read("git", "show", "-s", "--format=%cd", "--date=short", "HEAD", chdir: self).chuzzle
Utils.popen_read("git", "show", "-s", "--format=%cd", "--date=short", "HEAD", chdir: self).chomp.presence
end
end

View File

@ -1,10 +1,12 @@
# Contains backports from newer versions of Ruby
require "backports/2.4.0/string/match"
require "backports/2.5.0/string/delete_prefix"
require "active_support/core_ext/object/blank"
class String
# String.chomp, but if result is empty: returns nil instead.
# Allows `chuzzle || foo` short-circuits.
# TODO: Deprecate.
def chuzzle
s = chomp
s unless s.empty?
@ -12,6 +14,7 @@ class String
end
class NilClass
# TODO: Deprecate.
def chuzzle; end
end

View File

@ -7,6 +7,7 @@ require "pp"
require_relative "load_path"
require "active_support/core_ext/object/blank"
require "active_support/core_ext/numeric/time"
require "active_support/core_ext/array/access"
require "active_support/i18n"

View File

@ -722,7 +722,7 @@ class TapConfig
return unless Utils.git_available?
tap.path.cd do
Utils.popen_read("git", "config", "--local", "--get", "homebrew.#{key}").chuzzle
Utils.popen_read("git", "config", "--local", "--get", "homebrew.#{key}").chomp.presence
end
end

View File

@ -36,7 +36,7 @@ module Utils
@git_path ||= Utils.popen_read(
HOMEBREW_SHIMS_PATH/"scm/git", "--homebrew=print-path"
).chuzzle
).chomp.presence
end
def self.git_version