class Rambling::Trie::Serializers::Marshal

Serializer for Ruby marshal format (.marshal) files.

Attributes

serializer[R]

Public Class Methods

new(serializer = nil) click to toggle source

Creates a new Marshal serializer. @param [Serializer] serializer the serializer responsible to write to

and read from disk.
# File lib/rambling/trie/serializers/marshal.rb, line 11
def initialize serializer = nil
  @serializer = serializer || Rambling::Trie::Serializers::File.new
end

Public Instance Methods

dump(node, filepath) click to toggle source

Serializes a {Nodes::Node Node} and dumps it as a marshaled object into filepath. @param [Nodes::Node] node the node to serialize @param [String] filepath the full path of the file to dump the

marshaled object into.

@return [Numeric] number of bytes written to disk. @see ruby-doc.org/core-2.5.0/Marshal.html#method-c-dump

Marshal.dump
# File lib/rambling/trie/serializers/marshal.rb, line 38
def dump node, filepath
  serializer.dump ::Marshal.dump(node), filepath
end
load(filepath) click to toggle source

Loads marshaled object from contents in filepath and deserializes it into a {Nodes::Node Node}. @param [String] filepath the full path of the file to load the

marshaled object from.

@return [Nodes::Node] The deserialized {Nodes::Node Node}. @see ruby-doc.org/core-2.5.0/Marshal.html#method-c-load

Marshal.load

@note Use of

{https://ruby-doc.org/core-2.5.0/Marshal.html#method-c-load
Marshal.load} is generally discouraged. Only use this with trusted
input.
# File lib/rambling/trie/serializers/marshal.rb, line 26
def load filepath
  ::Marshal.load serializer.load filepath
end