Class: Rambling::Trie::Serializers::Yaml
- Inherits:
-
Object
- Object
- Rambling::Trie::Serializers::Yaml
- Defined in:
- lib/rambling/trie/serializers/yaml.rb
Overview
Serializer for Ruby yaml format (.yaml) files.
Instance Method Summary collapse
-
#dump(node, filepath) ⇒ Numeric
Serializes a Node and dumps it as a YAML object into filepath.
-
#initialize(serializer = nil) ⇒ Yaml
constructor
Creates a new Yaml serializer.
-
#load(filepath) ⇒ Nodes::Node
Loads serialized object from YAML file in filepath and deserializes it into a Node.
Constructor Details
#initialize(serializer = nil) ⇒ Yaml
Creates a new Yaml serializer.
11 12 13 |
# File 'lib/rambling/trie/serializers/yaml.rb', line 11 def initialize serializer = nil @serializer = serializer || Rambling::Trie::Serializers::File.new end |
Instance Method Details
#dump(node, filepath) ⇒ Numeric
Serializes a Node and dumps it as a YAML object into filepath.
44 45 46 47 |
# File 'lib/rambling/trie/serializers/yaml.rb', line 44 def dump node, filepath require 'yaml' serializer.dump ::YAML.dump(node), filepath end |
#load(filepath) ⇒ Nodes::Node
Loads serialized object from YAML file in filepath and deserializes it into a Node.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rambling/trie/serializers/yaml.rb', line 22 def load filepath require 'yaml' ::YAML.safe_load( serializer.load(filepath), [ Symbol, Rambling::Trie::Nodes::Raw, Rambling::Trie::Nodes::Compressed, ], [], true, ) end |