Class: Rambling::Trie::Serializers::Marshal
- Inherits:
-
Object
- Object
- 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.
11 12 13 |
# File 'lib/rambling/trie/serializers/marshal.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 marshaled object into filepath.
38 39 40 |
# File 'lib/rambling/trie/serializers/marshal.rb', line 38 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.
26 27 28 |
# File 'lib/rambling/trie/serializers/marshal.rb', line 26 def load filepath ::Marshal.load serializer.load filepath end |