class Rollbar::Truncation::StringsStrategy

Constants

STRING_THRESHOLDS

Public Class Methods

call(payload) click to toggle source
# File lib/rollbar/truncation/strings_strategy.rb, line 11
def self.call(payload)
  new.call(payload)
end

Public Instance Methods

call(payload) click to toggle source
# File lib/rollbar/truncation/strings_strategy.rb, line 15
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
truncate_strings_proc(threshold) click to toggle source
# File lib/rollbar/truncation/strings_strategy.rb, line 30
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