Class: Rambling::Trie::Serializers::Yaml
- Inherits:
-
Serializer
- Object
- Serializer
- Rambling::Trie::Serializers::Yaml
- Defined in:
- lib/rambling/trie/serializers/yaml.rb
Overview
Serializer for Ruby yaml format (‘.yaml`, or `.yml`) 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.
10 11 12 13 |
# File 'lib/rambling/trie/serializers/yaml.rb', line 10 def initialize serializer = nil super() @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.
37 38 39 40 |
# File 'lib/rambling/trie/serializers/yaml.rb', line 37 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.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rambling/trie/serializers/yaml.rb', line 19 def load filepath require 'yaml' ::YAML.safe_load( serializer.load(filepath), permitted_classes: [ Symbol, Rambling::Trie::Nodes::Raw, Rambling::Trie::Nodes::Compressed, ], aliases: true, ) end |