Class: Abroad::Serializers::Json::KeyValueSerializer

Inherits:
JsonSerializer show all
Defined in:
lib/abroad/serializers/json/key_value_serializer.rb

Constant Summary collapse

DEFAULT_INDENT_SPACES =
4

Constants inherited from Serializer

Serializer::DEFAULT_ENCODING

Instance Attribute Summary

Attributes inherited from JsonSerializer

#writer

Attributes inherited from Serializer

#locale, #options, #stream

Instance Method Summary collapse

Methods inherited from JsonSerializer

#flush, #write_raw

Methods inherited from Serializer

#encoding, #flush, from_stream, open, #write_raw

Constructor Details

#initialize(stream, locale, options = {}) ⇒ KeyValueSerializer

Returns a new instance of KeyValueSerializer.


8
9
10
11
# File 'lib/abroad/serializers/json/key_value_serializer.rb', line 8

def initialize(stream, locale, options = {})
  super
  writer.write_object
end

Instance Method Details

#closeObject


19
20
21
22
23
# File 'lib/abroad/serializers/json/key_value_serializer.rb', line 19

def close
  write_raw("\n") if pretty?
  writer.close_object
  super
end

#write_key_value(key, value) ⇒ Object


13
14
15
16
17
# File 'lib/abroad/serializers/json/key_value_serializer.rb', line 13

def write_key_value(key, value)
  writer.write_key_value(
    key.encode(encoding), value.encode(encoding), write_options
  )
end