Class: Rollbar::Truncation::StringsStrategy

Inherits:
Object
  • Object
show all
Includes:
Mixin
Defined in:
lib/rollbar/truncation/strings_strategy.rb

Constant Summary collapse

STRING_THRESHOLDS =
[1024, 512, 256]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin

#dump, #select_frames, #truncate?

Class Method Details

.call(payload) ⇒ Object



11
12
13
# File 'lib/rollbar/truncation/strings_strategy.rb', line 11

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

Instance Method Details

#call(payload) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rollbar/truncation/strings_strategy.rb', line 15

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

#truncate_strings_proc(threshold) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/rollbar/truncation/strings_strategy.rb', line 31

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