From ebfc3de878e9478b2eedbae82651dcfb3bf90d5b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonne=20Ha=C3=9F?= <me@mrzyx.de>
Date: Sun, 22 Jan 2012 15:38:55 +0100
Subject: [PATCH] do not require newrelic or airbrake unless they are
 configured

---
 Gemfile                         |  4 ++--
 app/models/app_config.rb        |  8 ++++++++
 config/initializers/airbrake.rb | 10 ++++++++++
 config/initializers/airbreak.rb | 13 -------------
 config/initializers/newrelic.rb |  7 +++++++
 5 files changed, 27 insertions(+), 15 deletions(-)
 create mode 100644 config/initializers/airbrake.rb
 delete mode 100644 config/initializers/airbreak.rb
 create mode 100644 config/initializers/newrelic.rb

diff --git a/Gemfile b/Gemfile
index d6f77787c1..55a5e22a10 100644
--- a/Gemfile
+++ b/Gemfile
@@ -28,8 +28,8 @@ gem 'messagebus_ruby_api', '1.0.1'
 
 group :production do # we don't install these on travis to speed up test runs
   # reporting
-  gem 'airbrake'
-  gem 'newrelic_rpm'
+  gem 'airbrake', :require => false
+  gem 'newrelic_rpm', :require => false
   gem 'rack-google-analytics', :require => 'rack/google-analytics'
   gem 'rack-piwik', :require => 'rack/piwik'
   gem 'rack-ssl', :require => 'rack/ssl'
diff --git a/app/models/app_config.rb b/app/models/app_config.rb
index 4f1deb544c..572c483aec 100644
--- a/app/models/app_config.rb
+++ b/app/models/app_config.rb
@@ -76,6 +76,7 @@ HELP
     normalize_pod_url
     normalize_admins
     normalize_pod_services
+    deprecate_hoptoad_api_key
   end
 
   def self.config_file_is_old_style?
@@ -127,6 +128,13 @@ HELP
     end
   end
 
+  def deprecate_hoptoad_api_key
+    if self[:hoptoad_api_key].present?
+      $stderr.puts "WARNING: Please change hoptoad_api_key to airbrake_api_key in your application.yml"
+      self[:airbrake_api_key] = self[:hoptoad_api_key]
+    end
+  end
+
   load!
 
   def self.[] (key)
diff --git a/config/initializers/airbrake.rb b/config/initializers/airbrake.rb
new file mode 100644
index 0000000000..6cc4ade864
--- /dev/null
+++ b/config/initializers/airbrake.rb
@@ -0,0 +1,10 @@
+# Copyright (c) 2012, Diaspora Inc.  This file is
+# licensed under the Affero General Public License version 3 or later.  See
+# the COPYRIGHT file.
+
+if AppConfig[:airbrake_api_key].present?
+  require 'airbrake'
+  Airbrake.configure do |config|
+    config.api_key = AppConfig[:airbrake_api_key]
+  end
+end
diff --git a/config/initializers/airbreak.rb b/config/initializers/airbreak.rb
deleted file mode 100644
index 904db41d0e..0000000000
--- a/config/initializers/airbreak.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# if old key still there, use it for new API,
-# update application.yml to use airbrake_api_key instead
-# (Former Hoptoad)
-if AppConfig[:airbrake_api_key].present?
-  Airbrake.configure do |config|
-    config.api_key = AppConfig[:airbrake_api_key]
-  end
-elsif AppConfig[:hoptoad_api_key].present?
-  puts "You're using old hoptoad_api_key, please update application.yml to use airbrake_api_key instead."
-  Airbrake.configure do |config|
-    config.api_key = AppConfig[:hoptoad_api_key]
-  end
-end
diff --git a/config/initializers/newrelic.rb b/config/initializers/newrelic.rb
new file mode 100644
index 0000000000..834fc0c242
--- /dev/null
+++ b/config/initializers/newrelic.rb
@@ -0,0 +1,7 @@
+# Copyright (c) 2012, Diaspora Inc.  This file is
+# licensed under the Affero General Public License version 3 or later.  See
+# the COPYRIGHT file.
+
+if EnviromentConfiguration.using_new_relic?
+  require 'newrelic_rpm'
+end
-- 
GitLab