Class: Parallel::ForkManager::Serializer
- Inherits:
-
Object
- Object
- Parallel::ForkManager::Serializer
- Defined in:
- lib/parallel/forkmanager/serializer.rb
Overview
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.
Instance Method Summary collapse
-
#deserialize(serialized) ⇒ Object
The resonstituted data structure.
-
#initialize(type) ⇒ Serializer
constructor
Raises a UnknownSerializerError exception if
typeisn’t one ofmarshaloryaml. -
#serialize(data_structure) ⇒ String
The serialized representation of the data.
Constructor Details
#initialize(type) ⇒ Serializer
Raises a UnknownSerializerError exception if type isn’t one of marshal or yaml
15 16 17 |
# File 'lib/parallel/forkmanager/serializer.rb', line 15 def initialize(type) @type = validate_type(type) end |
Instance Method Details
#deserialize(serialized) ⇒ Object
34 35 36 37 38 39 40 41 |
# 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) ⇒ String
22 23 24 25 26 27 28 29 |
# 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 |