Skip to content

Commit

Permalink
Rename PayloadTruncator to Truncator
Browse files Browse the repository at this point in the history
Simpler, shorter, better & still understandable.
  • Loading branch information
kyrylo committed May 13, 2017
1 parent 1a74f26 commit b844499
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions benchmarks/payload_truncator.rb → benchmarks/truncator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def self.generate
truncate_error_payload = Payload.generate
truncate_object_payload = Payload.generate

truncator = Airbrake::PayloadTruncator.new(TRUNCATOR_MAX_SIZE, LOGGER)
truncator = Airbrake::Truncator.new(TRUNCATOR_MAX_SIZE, LOGGER)

Benchmark.bm do |bm|
bm.report("PayloadTruncator#truncate_error ") do
bm.report("Truncator#truncate_error ") do
truncate_error_payload.each { |error| truncator.truncate_error(error) }
end

bm.report("PayloadTruncator#truncate_object") do
bm.report("Truncator#truncate_object") do
truncate_object_payload.each { |error| truncator.truncate_object(error) }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,28 @@ def generate(&block)
# Make sure we never truncate strings,
# because this is irrelevant to this benchmark.
MAX_PAYLOAD_SIZE = 1_000_000
truncator = Airbrake::PayloadTruncator.new(MAX_PAYLOAD_SIZE, Logger.new('/dev/null'))
truncator = Airbrake::Truncator.new(MAX_PAYLOAD_SIZE, Logger.new('/dev/null'))

Benchmark.bmbm do |bm|
bm.report("(worst case utf8) PayloadTruncator#truncate_string") do
bm.report("(worst case utf8) Truncator#truncate_string") do
worst_case_utf8.each do |str|
truncator.__send__(:truncate_string, str)
end
end

bm.report("(worst case ascii) PayloadTruncator#truncate_string") do
bm.report("(worst case ascii) Truncator#truncate_string") do
worst_case_ascii.each do |str|
truncator.__send__(:truncate_string, str)
end
end

bm.report("(mixed) PayloadTruncator#truncate_string") do
bm.report("(mixed) Truncator#truncate_string") do
mixed_case.each do |str|
truncator.__send__(:truncate_string, str)
end
end

bm.report("(best case) PayloadTruncator#truncate_string") do
bm.report("(best case) Truncator#truncate_string") do
best_case.each do |str|
truncator.__send__(:truncate_string, str)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/airbrake-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
require 'airbrake-ruby/nested_exception'
require 'airbrake-ruby/notice'
require 'airbrake-ruby/backtrace'
require 'airbrake-ruby/payload_truncator'
require 'airbrake-ruby/truncator'
require 'airbrake-ruby/filters'
require 'airbrake-ruby/filters/keys_filter'
require 'airbrake-ruby/filters/keys_whitelist'
Expand Down
2 changes: 1 addition & 1 deletion lib/airbrake-ruby/notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def initialize(config, exception, params = {})

extract_custom_attributes(exception)

@truncator = PayloadTruncator.new(PAYLOAD_MAX_SIZE, @config.logger)
@truncator = Truncator.new(PAYLOAD_MAX_SIZE, @config.logger)
end

##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Airbrake
#
# @api private
# @since v1.0.0
class PayloadTruncator
class Truncator
##
# @return [Hash] the options for +String#encode+
ENCODING_OPTIONS = { invalid: :replace, undef: :replace }.freeze
Expand Down
2 changes: 1 addition & 1 deletion spec/notice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def to_airbrake

context "when truncation failed" do
it "returns nil" do
expect_any_instance_of(Airbrake::PayloadTruncator).
expect_any_instance_of(Airbrake::Truncator).
to receive(:reduce_max_size).and_return(0)

encoded = Base64.encode64("\xD3\xE6\xBC\x9D\xBA").encode!('ASCII-8BIT')
Expand Down
2 changes: 1 addition & 1 deletion spec/sync_sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

context "when request body is nil" do
it "doesn't send a notice" do
expect_any_instance_of(Airbrake::PayloadTruncator).
expect_any_instance_of(Airbrake::Truncator).
to receive(:reduce_max_size).and_return(0)

encoded = Base64.encode64("\xD3\xE6\xBC\x9D\xBA").encode!('ASCII-8BIT')
Expand Down
2 changes: 1 addition & 1 deletion spec/payload_truncator_spec.rb → spec/truncator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'

RSpec.describe Airbrake::PayloadTruncator do
RSpec.describe Airbrake::Truncator do
let(:max_size) { 1000 }
let(:truncated_len) { '[Truncated]'.length }
let(:max_len) { max_size + truncated_len }
Expand Down

0 comments on commit b844499

Please sign in to comment.