Class: Rambling::Trie::Serializers::Marshal

Inherits:
Object
  • Object
show all
Defined in:
lib/rambling/trie/serializers/marshal.rb

Overview

Serializer for Ruby marshal format (.marshal) files.

Instance Method Summary collapse

Constructor Details

#initialize(serializer = nil) ⇒ Marshal

Creates a new Marshal serializer.

Parameters:

  • serializer (Serializer) (defaults to: nil)

    the serializer responsible to write to and read from disk.


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.

Parameters:

  • node (Nodes::Node)

    the node to serialize

  • filepath (String)

    the full path of the file to dump the marshaled object into.

Returns:

  • (Numeric)

    number of bytes written to disk.

See Also:


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.

Parameters:

  • filepath (String)

    the full path of the file to load the marshaled object from.

Returns:

See Also:


26
27
28
# File 'lib/rambling/trie/serializers/marshal.rb', line 26

def load filepath
  ::Marshal.load serializer.load filepath
end