Skip to content

Commit

Permalink
Silence method redifinition warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ojab committed Jul 8, 2021
1 parent 187a911 commit 8386c50
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def valid?
def sample_allowed?
return true if sample_rate == 1.0

if Random::DEFAULT.rand >= sample_rate
if Random.rand >= sample_rate
@errors << "Excluded by random sample"
false
else
Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def deep_dup
end

class Array
undef_method :deep_dup if method_defined?(:deep_dup)
# Returns a deep copy of array.
#
# array = [1, [2, 3]]
Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/lib/sentry/core_ext/object/duplicable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def duplicable?
end

class Method
undef_method :duplicable? if method_defined?(:duplicable?)
# Methods are not duplicable:
#
# method(:puts).duplicable? # => false
Expand Down
13 changes: 7 additions & 6 deletions sentry-ruby/lib/sentry/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
module Sentry
class Event
ATTRIBUTES = %i(
event_id level timestamp
release environment server_name modules
event_id release environment server_name modules
message user tags contexts extra
fingerprint breadcrumbs backtrace transaction
platform sdk type
)
platform sdk
).freeze
HASH_ATTRIBUTES = [*ATTRIBUTES, :level, :timestamp, :type].freeze

MAX_MESSAGE_SIZE_IN_BYTES = 1024 * 8

attr_accessor(*ATTRIBUTES)
attr_reader :configuration, :request, :exception, :threads
attr_reader :configuration, :request, :exception, :threads, :level, :timestamp
attr_writer :type

def initialize(configuration:, integration_meta: nil, message: nil)
# this needs to go first because some setters rely on configuration
Expand Down Expand Up @@ -139,7 +140,7 @@ def add_exception_interface(exception)
private

def serialize_attributes
self.class::ATTRIBUTES.each_with_object({}) do |att, memo|
self.class::HASH_ATTRIBUTES.each_with_object({}) do |att, memo|
if value = public_send(att)
memo[att] = value
end
Expand Down
7 changes: 5 additions & 2 deletions sentry-ruby/lib/sentry/transaction_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ class TransactionEvent < Event
TYPE = "transaction"

ATTRIBUTES = %i(
event_id level timestamp start_timestamp
event_id level timestamp
release environment server_name modules
user tags contexts extra
transaction platform sdk type
transaction platform sdk
)
HASH_ATTRIBUTES = [*ATTRIBUTES, :type, :start_timestamp, :spans].freeze

attr_accessor(*ATTRIBUTES)
attr_accessor :spans
attr_reader :start_timestamp
attr_writer :type

def start_timestamp=(time)
@start_timestamp = time.is_a?(Time) ? time.to_f : time
Expand Down
3 changes: 2 additions & 1 deletion sentry-ruby/lib/sentry/transport/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module Sentry
class Transport
class Configuration
attr_accessor :timeout, :open_timeout, :proxy, :ssl, :ssl_ca_file, :ssl_verification, :http_adapter, :faraday_builder,
:transport_class, :encoding
:encoding
attr_reader :transport_class

def initialize
@ssl_verification = true
Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/spec/sentry/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@
end

it 'captured_allowed false when sampled' do
allow(Random::DEFAULT).to receive(:rand).and_return(0.76)
allow(Random).to receive(:rand).and_return(0.76)
expect(subject.sending_allowed?).to eq(false)
expect(subject.errors).to eq(["Excluded by random sample"])
end

it 'captured_allowed true when not sampled' do
allow(Random::DEFAULT).to receive(:rand).and_return(0.74)
allow(Random).to receive(:rand).and_return(0.74)
expect(subject.sending_allowed?).to eq(true)
end
end
Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
it 'does not call #to_s for unnecessary env variables' do
expect(mock).not_to receive(:to_s)

interface = described_class.build(env: env)
described_class.build(env: env)
end
end
end
Expand Down Expand Up @@ -133,7 +133,7 @@ def to_s

new_env = env.merge("HTTP_FOO" => "BAR", "rails_object" => obj)

expect { interface = described_class.build(env: new_env) }.to_not raise_error
expect { described_class.build(env: new_env) }.to_not raise_error
end
end

Expand Down
10 changes: 1 addition & 9 deletions sentry-ruby/spec/sentry/net/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@
::Logger.new(string_io)
end

original_buffered_io = Net::BufferedIO

before(:all) do
Net.send(:const_set, :BufferedIO, Net::WebMockNetBufferedIO)
end

after(:all) do
Net.send(:const_set, :BufferedIO, original_buffered_io)
end
before { stub_const('Net::BufferedIO', Net::WebMockNetBufferedIO) }

class FakeSocket < StringIO
def setsockopt(*args); end
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/spec/sentry/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
before do
configuration.logger = Logger.new(string_io)
configuration.sample_rate = 0.5
allow(Random::DEFAULT).to receive(:rand).and_return(0.6)
allow(Random).to receive(:rand).and_return(0.6)
end

it "logs correct message" do
Expand Down

0 comments on commit 8386c50

Please sign in to comment.