Sha256: 85aad67a1f96976dc0272b009b55a544c781f8f26b7b883093f1e5dece8ea653

Contents?: true

Size: 1010 Bytes

Versions: 27

Compression:

Stored size: 1010 Bytes

Contents

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

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

      STRING_THRESHOLDS = [1024, 512, 256, 128].freeze

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

      def call(payload)
        result = nil

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

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

          break unless truncate?(result)
        end

        result
      end

      def truncate_strings_proc(threshold)
        proc do |value|
          # Rollbar::Util.truncate will operate on characters, not bytes,
          # so use value.length, not bytesize.
          if value.is_a?(String) && value.length > threshold
            Rollbar::Util.truncate(value, threshold)
          else
            value
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rollbar-3.6.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.5.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.5.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.5.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.4.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.4.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.4.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.3.3 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.3.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.3.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.3.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.2.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.1.2 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.1.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.1.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.0.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-3.0.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.27.1 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.27.0 lib/rollbar/truncation/strings_strategy.rb
rollbar-2.26.1 lib/rollbar/truncation/strings_strategy.rb