Class: Airbrake::Truncator Private
- Inherits:
-
Object
- Object
- Airbrake::Truncator
- Defined in:
- lib/airbrake-ruby/truncator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class is responsible for truncation of too big objects. Mainly, you should use it for simple objects such as strings, hashes, & arrays.
Constant Summary collapse
- ENCODING_OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns the options for String#encode.
{ invalid: :replace, undef: :replace }.freeze
- TEMP_ENCODING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns the temporary encoding to be used when fixing invalid strings with
ENCODING_OPTIONS
. 'utf-16'.freeze
- SUPPORTED_ENCODINGS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns encodings that are eligible for fixing invalid characters.
[Encoding::UTF_8, Encoding::ASCII].freeze
- CIRCULAR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns what to append when something is a circular reference.
'[Circular]'.freeze
- TRUNCATED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns what to append when something is truncated.
'[Truncated]'.freeze
- CIRCULAR_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns The types that can contain references to itself.
[Array, Hash, Set].freeze
Instance Method Summary collapse
-
#initialize(max_size) ⇒ Truncator
constructor
private
A new instance of Truncator.
-
#reduce_max_size ⇒ Integer
private
Reduces maximum allowed size of hashes, arrays, sets & strings by half.
-
#truncate(object, seen = Set.new) ⇒ Object
private
Performs deep truncation of arrays, hashes, sets & strings.
Constructor Details
#initialize(max_size) ⇒ Truncator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Truncator.
29 30 31 |
# File 'lib/airbrake-ruby/truncator.rb', line 29 def initialize(max_size) @max_size = max_size end |
Instance Method Details
#reduce_max_size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reduces maximum allowed size of hashes, arrays, sets & strings by half.
50 51 52 |
# File 'lib/airbrake-ruby/truncator.rb', line 50 def reduce_max_size @max_size /= 2 end |
#truncate(object, seen = Set.new) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Performs deep truncation of arrays, hashes, sets & strings. Uses a placeholder for recursive objects (‘[Circular]`).
39 40 41 42 43 44 45 46 |
# File 'lib/airbrake-ruby/truncator.rb', line 39 def truncate(object, seen = Set.new) if seen.include?(object.object_id) return CIRCULAR if CIRCULAR_TYPES.any? { |t| object.is_a?(t) } return object end truncate_object(object, seen << object.object_id) end |