Class: Julewire::Core::Serialization::JsonEncoder
- Inherits:
-
Object
- Object
- Julewire::Core::Serialization::JsonEncoder
- Defined in:
- lib/julewire/core/serialization/json_encoder.rb
Instance Method Summary collapse
- #call(payload) ⇒ Object
-
#initialize(max_depth: Serializer::DEFAULT_MAX_DEPTH, max_string_bytes: Serializer::DEFAULT_MAX_STRING_BYTES, max_array_items: Serializer::DEFAULT_MAX_ARRAY_ITEMS, max_hash_keys: Serializer::DEFAULT_MAX_HASH_KEYS, compact_empty: true, max_backtrace_lines: Core::MAX_BACKTRACE_LINES, append_newline: true) ⇒ JsonEncoder
constructor
A new instance of JsonEncoder.
Constructor Details
#initialize(max_depth: Serializer::DEFAULT_MAX_DEPTH, max_string_bytes: Serializer::DEFAULT_MAX_STRING_BYTES, max_array_items: Serializer::DEFAULT_MAX_ARRAY_ITEMS, max_hash_keys: Serializer::DEFAULT_MAX_HASH_KEYS, compact_empty: true, max_backtrace_lines: Core::MAX_BACKTRACE_LINES, append_newline: true) ⇒ JsonEncoder
Returns a new instance of JsonEncoder.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/julewire/core/serialization/json_encoder.rb', line 10 def initialize( max_depth: Serializer::DEFAULT_MAX_DEPTH, max_string_bytes: Serializer::DEFAULT_MAX_STRING_BYTES, max_array_items: Serializer::DEFAULT_MAX_ARRAY_ITEMS, max_hash_keys: Serializer::DEFAULT_MAX_HASH_KEYS, compact_empty: true, max_backtrace_lines: Core::MAX_BACKTRACE_LINES, append_newline: true ) @max_depth = max_depth @max_string_bytes = max_string_bytes @max_array_items = max_array_items @max_hash_keys = max_hash_keys @compact_empty = compact_empty @max_backtrace_lines = max_backtrace_lines @line_suffix = append_newline ? "\n" : "" @serializer_key = [ @max_depth, @max_string_bytes, @max_array_items, @max_hash_keys, @compact_empty, @max_backtrace_lines ].freeze end |
Instance Method Details
#call(payload) ⇒ Object
36 37 38 39 40 |
# File 'lib/julewire/core/serialization/json_encoder.rb', line 36 def call(payload) JSON.generate(serialized_payload(payload), allow_nan: false).tap do |json| json << @line_suffix end end |