Class: Rambling::Trie::Serializers::Yaml
- Inherits:
-
Serializer
- Object
- Serializer
- Rambling::Trie::Serializers::Yaml
- Defined in:
- lib/rambling/trie/serializers/yaml.rb,
sig/lib/rambling/trie/serializers/yaml.rbs
Overview
Serializer for Ruby yaml format (.yaml, or .yml) files.
Instance Attribute Summary collapse
-
#serializer ⇒ Serializer[String]
readonly
Returns the value of attribute serializer.
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 Attribute Details
#serializer ⇒ Serializer[String] (readonly)
Returns the value of attribute serializer.
49 50 51 |
# File 'lib/rambling/trie/serializers/yaml.rb', line 49 def serializer @serializer end |
Instance Method Details
#dump(node, filepath) ⇒ Numeric
Serializes a Node and dumps it as a YAML object into filepath.
42 43 44 45 |
# File 'lib/rambling/trie/serializers/yaml.rb', line 42 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 31 32 33 34 35 |
# File 'lib/rambling/trie/serializers/yaml.rb', line 19 def load filepath warn <<~WARN.chomp.tr("\n", ' ') WARNING: YAML aliases are enabled. Loading untrusted YAML with aliases: true can trigger a billion-laughs memory attack. Only load YAML data from trusted sources. WARN require 'yaml' ::YAML.safe_load( serializer.load(filepath), permitted_classes: [ Symbol, Rambling::Trie::Nodes::Raw, Rambling::Trie::Nodes::Compressed, ], aliases: true, ) end |