From d47fe381e9376bba4c8f6857f40586dec3c0658b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Pi=C4=85tyszek?= Date: Tue, 19 Jan 2016 08:14:08 +0100 Subject: [PATCH 1/3] Make it compatible with Rollbar gem's rake patch When exception_notification-rake and rollbar-gem are both used, notifications about exceptions in rake tasks don't get sent to Rollbar. --- lib/exception_notifier/rake/rake_patch.rb | 25 ++++++++--------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/exception_notifier/rake/rake_patch.rb b/lib/exception_notifier/rake/rake_patch.rb index 11584b6..c003d75 100644 --- a/lib/exception_notifier/rake/rake_patch.rb +++ b/lib/exception_notifier/rake/rake_patch.rb @@ -1,18 +1,15 @@ -# Monkey patching patterns lifted from -# https://github.com/thoughtbot/airbrake/blob/master/lib/airbrake/rake_handler.rb module ExceptionNotifier module RakePatch - def self.included(klass) - klass.class_eval do + def self.patch! + ::Rake::Application.class_eval do alias_method :display_error_message_without_notifications, :display_error_message - alias_method :display_error_message, :display_error_message_with_notifications - end - end - def display_error_message_with_notifications(ex) - display_error_message_without_notifications(ex) - ExceptionNotifier::Rake.maybe_deliver_notification(ex, - :rake_command_line => reconstruct_command_line) + def display_error_message(ex) + display_error_message_without_notifications(ex) + ExceptionNotifier::Rake.maybe_deliver_notification(ex, + :rake_command_line => reconstruct_command_line) + end + end end def reconstruct_command_line @@ -24,9 +21,5 @@ def reconstruct_command_line # Only do this if we're actually in a Rake context. In some contexts (e.g., # in the Rails console) Rake might not be defined. if Object.const_defined? :Rake - Rake.application.instance_eval do - class << self - include ExceptionNotifier::RakePatch - end - end + ExceptionNotifier::RakePatch.patch! end From d253e5d7354016106637916eae91e83f3bfca0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Pi=C4=85tyszek?= Date: Tue, 19 Jan 2016 11:47:20 +0100 Subject: [PATCH 2/3] Make reconstruct_command_line method accessible --- lib/exception_notifier/rake/rake_patch.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/exception_notifier/rake/rake_patch.rb b/lib/exception_notifier/rake/rake_patch.rb index c003d75..51e7747 100644 --- a/lib/exception_notifier/rake/rake_patch.rb +++ b/lib/exception_notifier/rake/rake_patch.rb @@ -9,11 +9,11 @@ def display_error_message(ex) ExceptionNotifier::Rake.maybe_deliver_notification(ex, :rake_command_line => reconstruct_command_line) end - end - end - def reconstruct_command_line - "rake #{ARGV.join(' ')}" + def reconstruct_command_line + "rake #{ARGV.join(' ')}" + end + end end end end From 194e6a8ed480060f609b147abb808fc435caac3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Pi=C4=85tyszek?= Date: Tue, 19 Jan 2016 12:34:32 +0100 Subject: [PATCH 3/3] Add rake requirement to avoid problems with testing Running tests on RubyMine doesn't work without this. --- lib/exception_notifier/rake/rake_patch.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/exception_notifier/rake/rake_patch.rb b/lib/exception_notifier/rake/rake_patch.rb index 51e7747..c9ac898 100644 --- a/lib/exception_notifier/rake/rake_patch.rb +++ b/lib/exception_notifier/rake/rake_patch.rb @@ -1,3 +1,5 @@ +require 'rake' + module ExceptionNotifier module RakePatch def self.patch!