Sha256: 4595575c7968821d1c652553e7d0fef09f0662e09d024ee58132efeaaa6fab65

Contents?: true

Size: 942 Bytes

Versions: 23

Compression:

Stored size: 942 Bytes

Contents

require 'rollbar/util'
require 'rollbar/truncation/mixin'

module Rollbar
  module Truncation
    class StringsStrategy
      include ::Rollbar::Truncation::Mixin

      STRING_THRESHOLDS = [1024, 512, 256]

      def self.call(payload)
        new.call(payload)
      end

      def call(payload)
        result = nil
        new_payload = Rollbar::Util.deep_copy(payload)

        STRING_THRESHOLDS.each do |threshold|
          truncate_proc = truncate_strings_proc(threshold)

          ::Rollbar::Util.iterate_and_update(new_payload, truncate_proc)
          result = dump(new_payload)

          break unless truncate?(result)
        end

        result
      end

      def truncate_strings_proc(threshold)
        proc do |value|
          if value.is_a?(String) && value.bytesize > threshold
            Rollbar::Util.truncate(value, threshold)
          else
            value
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rollbar-2.19.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.19.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.19.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.18.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.18.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.17.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.16.4 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.16.3 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.16.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.16.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.15.6 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.15.5 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.15.4 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.15.3 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.15.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.15.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.15.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.14.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.14.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.13.3 lib/rollbar/truncation/strings_strategy.rb