Sha256: a378a4008ac319335f97be0802ae6d9eefda6c33bcdec74003f5cbceff0b4923

Contents?: true

Size: 923 Bytes

Versions: 49

Compression:

Stored size: 923 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 = payload.clone

        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

49 entries across 49 versions & 1 rubygems

Version Path
rollbar-2.12.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.11.5 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.11.4 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.11.3 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.11.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.11.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.11.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.10.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.9.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.9.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.8.3 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.8.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.8.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.8.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.7.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.7.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.6.3 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.6.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.6.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.6.0 lib/rollbar/truncation/strings_strategy.rb