Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Rake support to avoid conflicts with other services #517

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
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
38 changes: 32 additions & 6 deletions lib/rollbar/plugins/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,57 @@

module Rollbar
module Rake
class << self
attr_accessor :patched
end

module Handler
def self.included(base)
base.class_eval do
alias_method :orig_display_error_message, :display_error_message
alias_method :display_error_message, :display_error_message_with_rollbar
end
end

def display_error_message_with_rollbar(ex)
Rollbar.error(ex, :use_exception_level_filters => true)
orig_display_error_message(ex)
end
end

def self.patch!
skip_patch && return unless patch?
unless patch?
skip_patch

::Rake::Application.class_eval do
alias_method :orig_display_error_message, :display_error_message
return
end

def display_error_message(ex)
Rollbar.error(ex, :use_exception_level_filters => true)
orig_display_error_message(ex)
::Rake.application.instance_eval do
class << self
include ::Rollbar::Rake::Handler
end
end

self.patched = true
end

def self.skip_patch
warn('[Rollbar] Rollbar is disabled for Rake tasks since your Rake version is under 0.9.x. Please upgrade to 0.9.x or higher.')
end

def self.patch?
return false if patched?
return false unless rake_version

major, minor, = rake_version.split('.').map(&:to_i)

major > 0 || major == 0 && minor > 8
end

def self.patched?
patched
end

def self.rake_version
if Object.const_defined?('RAKEVERSION')
return RAKEVERSION
Expand Down
3 changes: 1 addition & 2 deletions spec/rollbar/plugins/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Rollbar.plugins.load!

describe Rollbar::Rake do
let(:application) { Rake::Application.new }
let(:application) { Rake.application }
let(:exception) { Exception.new }

context 'with supported rake version' do
Expand All @@ -12,7 +12,6 @@
end

it 'reports error to Rollbar' do
expect(Rollbar::Rake).not_to receive(:skip_patch)
expect(Rollbar).to receive(:error).with(exception, :use_exception_level_filters => true)
expect(application).to receive(:orig_display_error_message).with(exception)

Expand Down