Skip to content

Commit

Permalink
Changed: Use #prepend over #alias_method for Thread plugin. (#1018)
Browse files Browse the repository at this point in the history
  • Loading branch information
delner authored Dec 9, 2020
1 parent ade7862 commit 310a9d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/rollbar/plugins/thread.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Rollbar.plugins.define('thread') do
execute do
Thread.class_eval do
def initialize_with_rollbar(*args, &block)
module Rollbar
module ThreadPlugin
def initialize(*args)
self[:_rollbar_notifier] ||= Rollbar.notifier.scope
initialize_without_rollbar(*args, &block)
super
end

alias_method :initialize_without_rollbar, :initialize
alias_method :initialize, :initialize_with_rollbar
end
end

execute do
Thread.send(:prepend, Rollbar::ThreadPlugin) # rubocop:disable Lint/SendWithMixinArgument
end
end
11 changes: 11 additions & 0 deletions spec/rollbar/plugins/thread_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'

Rollbar.plugins.load!

describe Rollbar::ThreadPlugin do
subject(:thread) { Thread.new {} }

it 'has a Rollbar notifier' do
expect(thread[:_rollbar_notifier]).to be_a_kind_of(Rollbar::Notifier)
end
end

0 comments on commit 310a9d1

Please sign in to comment.