Class: Abroad::Serializers::Json::DottedKeySerializer

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

Constant Summary

Constants inherited from Serializer

Serializer::DEFAULT_ENCODING

Instance Attribute Summary collapse

Attributes inherited from JsonSerializer

#writer

Attributes inherited from Serializer

#locale, #options, #stream

Instance Method Summary collapse

Methods inherited from JsonSerializer

#write_raw

Methods inherited from Serializer

#close, #encoding, from_stream, open, #write_raw

Constructor Details

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

Returns a new instance of DottedKeySerializer.



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

def initialize(stream, locale, options = {})
  super
  @trie = Abroad::Serializers::Trie.new
end

Instance Attribute Details

#trieObject (readonly)

Returns the value of attribute trie.



6
7
8
# File 'lib/abroad/serializers/json/dotted_key_serializer.rb', line 6

def trie
  @trie
end

Instance Method Details

#flushObject



17
18
19
20
21
# File 'lib/abroad/serializers/json/dotted_key_serializer.rb', line 17

def flush
  write_node(trie.root, nil)
  writer.flush
  stream.flush
end

#write_key_value(key, value) ⇒ Object



13
14
15
# File 'lib/abroad/serializers/json/dotted_key_serializer.rb', line 13

def write_key_value(key, value)
  trie.add(key.split('.'), encode(value))
end