class Parallel::ForkManager::Serializer
TODO: Maybe make this into a factory, given the number of case statements switching on type. This is a “shameless green” if you use Sandi Metz's terminology.
Attributes
type[R]
Public Class Methods
new(type)
click to toggle source
Raises a {Parallel::ForkManager::UnknownSerializerError} exception if type
isn't one of marshal
or yaml
@param type [String] The type of serialization to use.
# File lib/parallel/forkmanager/serializer.rb, line 15 def initialize(type) @type = validate_type(type) end
Public Instance Methods
deserialize(serialized)
click to toggle source
@param serialized [String] the serialized representation of the data. @return [Object] the resonstituted data structure.
# File lib/parallel/forkmanager/serializer.rb, line 34 def deserialize(serialized) case type when :marshal Marshal.load(serialized) when :yaml YAML.load(serialized) end end
serialize(data_structure)
click to toggle source
@param data_structure [Object] the data to be serialized. @return [String] the serialized representation of the data.
# File lib/parallel/forkmanager/serializer.rb, line 22 def serialize(data_structure) case type when :marshal Marshal.dump(data_structure) when :yaml YAML.dump(data_structure) end end
Private Instance Methods
validate_type(t)
click to toggle source
# File lib/parallel/forkmanager/serializer.rb, line 47 def validate_type(t) case t.downcase when "marshal" :marshal when "yaml" :yaml else fail Parallel::ForkManager::UnknownSerializerError end end