Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions lib/exception_notifier/rake/rake_patch.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
# Monkey patching patterns lifted from
# https://github.com/thoughtbot/airbrake/blob/master/lib/airbrake/rake_handler.rb
require 'rake'

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)
end
def display_error_message(ex)
display_error_message_without_notifications(ex)
ExceptionNotifier::Rake.maybe_deliver_notification(ex,
:rake_command_line => reconstruct_command_line)
end

def reconstruct_command_line
"rake #{ARGV.join(' ')}"
def reconstruct_command_line
"rake #{ARGV.join(' ')}"
end
end
end
end
end

# 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