Class: Nanite::Serializer

Inherits:
Object show all
Defined in:
lib/nanite/serializer.rb

Defined Under Namespace

Classes: SerializationError

Instance Method Summary collapse

Constructor Details

#initialize(preferred_format = :marshal) ⇒ Serializer

The secure serializer should not be part of the cascading



14
15
16
17
18
19
20
21
22
23
# File 'lib/nanite/serializer.rb', line 14

def initialize(preferred_format = :marshal)
  preferred_format ||= :marshal
  if preferred_format.to_s == 'secure'
    @serializers = [ SecureSerializer ]
  else
    preferred_serializer = SERIALIZERS[preferred_format.to_sym]
    @serializers = SERIALIZERS.values.clone
    @serializers.unshift(@serializers.delete(preferred_serializer)) if preferred_serializer
  end
end

Instance Method Details

#dump(packet) ⇒ Object



25
26
27
# File 'lib/nanite/serializer.rb', line 25

def dump(packet)
  cascade_serializers(:dump, packet)
end

#load(packet) ⇒ Object



29
30
31
# File 'lib/nanite/serializer.rb', line 29

def load(packet)
  cascade_serializers(:load, packet)
end