Skip to content

Commit 310a9d1

Browse files
authored
Changed: Use #prepend over #alias_method for Thread plugin. (#1018)
1 parent ade7862 commit 310a9d1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/rollbar/plugins/thread.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Rollbar.plugins.define('thread') do
2-
execute do
3-
Thread.class_eval do
4-
def initialize_with_rollbar(*args, &block)
2+
module Rollbar
3+
module ThreadPlugin
4+
def initialize(*args)
55
self[:_rollbar_notifier] ||= Rollbar.notifier.scope
6-
initialize_without_rollbar(*args, &block)
6+
super
77
end
8-
9-
alias_method :initialize_without_rollbar, :initialize
10-
alias_method :initialize, :initialize_with_rollbar
118
end
129
end
10+
11+
execute do
12+
Thread.send(:prepend, Rollbar::ThreadPlugin) # rubocop:disable Lint/SendWithMixinArgument
13+
end
1314
end

spec/rollbar/plugins/thread_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'spec_helper'
2+
3+
Rollbar.plugins.load!
4+
5+
describe Rollbar::ThreadPlugin do
6+
subject(:thread) { Thread.new {} }
7+
8+
it 'has a Rollbar notifier' do
9+
expect(thread[:_rollbar_notifier]).to be_a_kind_of(Rollbar::Notifier)
10+
end
11+
end

0 commit comments

Comments
 (0)