Class: Rambling::Trie::Serializers::Marshal
- Inherits:
-
Serializer
- Object
- Serializer
- Rambling::Trie::Serializers::Marshal
- Defined in:
- lib/rambling/trie/serializers/marshal.rb
Overview
Serializer for Ruby marshal format (.marshal
) files.
Instance Method Summary collapse
-
#dump(node, filepath) ⇒ Numeric
Serializes a Node and dumps it as a marshaled object into filepath.
-
#initialize(serializer = nil) ⇒ Marshal
constructor
Creates a new Marshal serializer.
-
#load(filepath) ⇒ Nodes::Node
Loads marshaled object from contents in filepath and deserializes it into a Node.
Constructor Details
#initialize(serializer = nil) ⇒ Marshal
Creates a new Marshal serializer.
10 11 12 13 |
# File 'lib/rambling/trie/serializers/marshal.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 marshaled object into filepath.
30 31 32 |
# File 'lib/rambling/trie/serializers/marshal.rb', line 30 def dump node, filepath serializer.dump ::Marshal.dump(node), filepath end |
#load(filepath) ⇒ Nodes::Node
Note:
Use of Marshal.load is generally discouraged. Only use this with trusted input.
Loads marshaled object from contents in filepath and deserializes it into a Node.
21 22 23 |
# File 'lib/rambling/trie/serializers/marshal.rb', line 21 def load filepath ::Marshal.load serializer.load filepath end |