Class: Parallel::ForkManager::Serializer

Inherits:
Object
  • Object
show all
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

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