aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2016-05-03 14:21:08 +0100
committerMike McQuaid2016-05-03 14:21:08 +0100
commit0ef21ddf8707289fdf4ef0ad19223f0ba4862f52 (patch)
treef531668a133bea9b3ca32aa5681a4cf79166ddc9 /Library
parent798c342f4e3c27ea57072712ef7056be60f041c3 (diff)
downloadbrew-0ef21ddf8707289fdf4ef0ad19223f0ba4862f52.tar.bz2
analytics: move to a class.
Global namespaces are good to avoid when possible.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formula_installer.rb2
-rw-r--r--Library/Homebrew/utils/analytics.rb124
-rw-r--r--Library/brew.rb6
3 files changed, 69 insertions, 63 deletions
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb
index 3ce7117b0..4de4a79dc 100644
--- a/Library/Homebrew/formula_installer.rb
+++ b/Library/Homebrew/formula_installer.rb
@@ -204,7 +204,7 @@ class FormulaInstaller
if formula.tap && !formula.tap.private?
options = effective_build_options_for(formula).used_options.to_a.join(" ")
- report_analytics_event("install", "#{formula.full_name} #{options}".strip)
+ Utils::Analytics.report_event("install", "#{formula.full_name} #{options}".strip)
end
@@attempted << formula
diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb
index 32ea22f89..10cf2affa 100644
--- a/Library/Homebrew/utils/analytics.rb
+++ b/Library/Homebrew/utils/analytics.rb
@@ -1,67 +1,73 @@
-def analytics_label
- @analytics_anonymous_prefix_and_os ||= begin
- os = OS_VERSION
- prefix = ", non-/usr/local" if HOMEBREW_PREFIX.to_s != "/usr/local"
- ci = ", CI" if ENV["CI"]
- "#{os}#{prefix}#{ci}"
- end
-end
+module Utils
+ module Analytics
+ class << self
+ def os_prefix_ci
+ @anonymous_os_prefix_ci ||= begin
+ os = OS_VERSION
+ prefix = ", non-/usr/local" if HOMEBREW_PREFIX.to_s != "/usr/local"
+ ci = ", CI" if ENV["CI"]
+ "#{os}#{prefix}#{ci}"
+ end
+ end
-def report_analytics(type, metadata = {})
- return if ENV["HOMEBREW_NO_ANALYTICS"] || ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"]
+ def report(type, metadata = {})
+ return if ENV["HOMEBREW_NO_ANALYTICS"] || ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"]
- args = %W[
- --max-time 3
- --user-agent #{HOMEBREW_USER_AGENT_CURL}
- -d v=1
- -d tid=#{ENV["HOMEBREW_ANALYTICS_ID"]}
- -d cid=#{ENV["HOMEBREW_ANALYTICS_USER_UUID"]}
- -d aip=1
- -d an=#{HOMEBREW_PRODUCT}
- -d av=#{HOMEBREW_VERSION}
- -d t=#{type}
- ]
- metadata.each { |k, v| args << "-d" << "#{k}=#{v}" if k && v }
+ args = %W[
+ --max-time 3
+ --user-agent #{HOMEBREW_USER_AGENT_CURL}
+ -d v=1
+ -d tid=#{ENV["HOMEBREW_ANALYTICS_ID"]}
+ -d cid=#{ENV["HOMEBREW_ANALYTICS_USER_UUID"]}
+ -d aip=1
+ -d an=#{HOMEBREW_PRODUCT}
+ -d av=#{HOMEBREW_VERSION}
+ -d t=#{type}
+ ]
+ metadata.each { |k, v| args << "-d" << "#{k}=#{v}" if k && v }
- # Send analytics. Don't send or store any personally identifiable information.
- # https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Analytics.md
- # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
- # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
- if ENV["HOMEBREW_ANALYTICS_DEBUG"]
- puts Utils.popen_read ENV["HOMEBREW_CURL"],
- "https://www.google-analytics.com/debug/collect",
- *args
- else
- pid = fork do
- exec ENV["HOMEBREW_CURL"],
- "https://www.google-analytics.com/collect",
- "--silent", "--output", "/dev/null",
- *args
- end
- Process.detach pid
- end
-end
+ # Send analytics. Don't send or store any personally identifiable information.
+ # https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Analytics.md
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
+ if ENV["HOMEBREW_ANALYTICS_DEBUG"]
+ puts Utils.popen_read ENV["HOMEBREW_CURL"],
+ "https://www.google-analytics.com/debug/collect",
+ *args
+ else
+ pid = fork do
+ exec ENV["HOMEBREW_CURL"],
+ "https://www.google-analytics.com/collect",
+ "--silent", "--output", "/dev/null",
+ *args
+ end
+ Process.detach pid
+ end
+ end
-def report_analytics_event(category, action, label = analytics_label, value = nil)
- report_analytics(:event,
- :ec => category,
- :ea => action,
- :el => label,
- :ev => value)
-end
+ def report_event(category, action, label = os_prefix_ci, value = nil)
+ report(:event,
+ :ec => category,
+ :ea => action,
+ :el => label,
+ :ev => value)
+ end
-def report_analytics_exception(exception, options = {})
- if exception.is_a?(BuildError) &&
- exception.formula.tap && !exception.formula.tap.private?
- report_analytics_event("BuildError", exception.formula.full_name)
- end
+ def report_exception(exception, options = {})
+ if exception.is_a?(BuildError) &&
+ exception.formula.tap && !exception.formula.tap.private?
+ report_event("BuildError", exception.formula.full_name)
+ end
- fatal = options.fetch(:fatal, true) ? "1" : "0"
- report_analytics(:exception,
- :exd => exception.class.name,
- :exf => fatal)
-end
+ fatal = options.fetch(:fatal, true) ? "1" : "0"
+ report(:exception,
+ :exd => exception.class.name,
+ :exf => fatal)
+ end
-def report_analytics_screenview(screen_name)
- report_analytics(:screenview, :cd => screen_name)
+ def report_screenview(screen_name)
+ report(:screenview, :cd => screen_name)
+ end
+ end
+ end
end
diff --git a/Library/brew.rb b/Library/brew.rb
index c7447348f..b72e24d3d 100644
--- a/Library/brew.rb
+++ b/Library/brew.rb
@@ -129,17 +129,17 @@ rescue Interrupt => e
$stderr.puts # seemingly a newline is typical
exit 130
rescue BuildError => e
- report_analytics_exception(e)
+ Utils::Analytics.report_exception(e)
e.dump
exit 1
rescue RuntimeError, SystemCallError => e
- report_analytics_exception(e)
+ Utils::Analytics.report_exception(e)
raise if e.message.empty?
onoe e
$stderr.puts e.backtrace if ARGV.debug?
exit 1
rescue Exception => e
- report_analytics_exception(e)
+ Utils::Analytics.report_exception(e)
onoe e
if internal_cmd
$stderr.puts "#{Tty.white}Please report this bug:"