Class: BerkeleyLibrary::Logging::SafeSerializer
- Inherits:
-
Object
- Object
- BerkeleyLibrary::Logging::SafeSerializer
- Includes:
- ExceptionSerializer
- Defined in:
- lib/berkeley_library/logging/safe_serializer.rb
Overview
Some of values include recursive structures that cause SystemStackErrors in JSON serialization, so we convert them all to strings
Constant Summary collapse
- RAW_TYPES =
[NilClass, FalseClass, TrueClass, Numeric, String, Symbol, Date, Time].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ SafeSerializer
constructor
A new instance of SafeSerializer.
- #serialized_value ⇒ Object
Methods included from ExceptionSerializer
Constructor Details
#initialize(value) ⇒ SafeSerializer
Returns a new instance of SafeSerializer.
14 15 16 |
# File 'lib/berkeley_library/logging/safe_serializer.rb', line 14 def initialize(value) @value = value end |
Class Method Details
.placeholder_for(value) ⇒ Object
23 24 25 |
# File 'lib/berkeley_library/logging/safe_serializer.rb', line 23 def placeholder_for(value) "#<#{value.class}:#{value.object_id}> (recursive reference)" end |
.serialize(value) ⇒ Object
19 20 21 |
# File 'lib/berkeley_library/logging/safe_serializer.rb', line 19 def serialize(value) SafeSerializer.new(value).serialized_value end |
Instance Method Details
#serialized_value ⇒ Object
28 29 30 |
# File 'lib/berkeley_library/logging/safe_serializer.rb', line 28 def serialized_value @serialized_value ||= serialize(@value) end |