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

Inherits:
Serializer
  • 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.



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.

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:



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.

Parameters:

  • filepath (String)

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

Returns:

See Also:



21
22
23
# File 'lib/rambling/trie/serializers/marshal.rb', line 21

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