Class: Nanite::Serializer
Defined Under Namespace
Classes: SerializationError
Constant Summary collapse
- SERIALIZERS =
{:json => JSON, :marshal => Marshal, :yaml => YAML}.freeze
Instance Attribute Summary collapse
-
#preferred_format ⇒ Object
readonly
Returns the value of attribute preferred_format.
Instance Method Summary collapse
- #dump(packet, format = nil) ⇒ Object
-
#initialize(preferred_format = nil) ⇒ Serializer
constructor
The secure serializer should not be part of the cascading.
- #load(packet, format = nil) ⇒ Object
Constructor Details
#initialize(preferred_format = nil) ⇒ Serializer
The secure serializer should not be part of the cascading
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/nanite/serializer.rb', line 17 def initialize(preferred_format = nil) @preferred_format = 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 Attribute Details
#preferred_format ⇒ Object (readonly)
Returns the value of attribute preferred_format.
5 6 7 |
# File 'lib/nanite/serializer.rb', line 5 def preferred_format @preferred_format end |
Instance Method Details
#dump(packet, format = nil) ⇒ Object
28 29 30 |
# File 'lib/nanite/serializer.rb', line 28 def dump(packet, format = nil) cascade_serializers(:dump, packet, format) end |
#load(packet, format = nil) ⇒ Object
32 33 34 |
# File 'lib/nanite/serializer.rb', line 32 def load(packet, format = nil) cascade_serializers(:load, packet, format) end |