Class: Ruote::Serializer
- Inherits:
-
Object
- Object
- Ruote::Serializer
- Defined in:
- lib/ruote/util/serializer.rb
Overview
Constant Summary collapse
- MARSHAL =
plain marshal serialization
[ lambda { }, lambda { |o| Marshal.dump(o) }, lambda { |s| Marshal.load(s) } ]
- MARSHAL64 =
marshal serialization with base64 encoding
[ lambda { require 'base64' }, lambda { |o| Base64.encode64(Marshal.dump(o)) }, lambda { |s| Marshal.load(Base64.decode64(s)) } ]
- YAML =
YAML serialization
[ lambda { require 'yaml' }, lambda { |o| ::YAML.dump(o) }, lambda { |s| ::YAML.load(s) } ]
- FLAVOURS =
The flavour map
{ :marshal => MARSHAL, :marshal64 => MARSHAL64, :yaml => YAML }
Instance Method Summary collapse
- #decode(s) ⇒ Object
- #encode(o) ⇒ Object
-
#initialize(flavour) ⇒ Serializer
constructor
A new instance of Serializer.
Constructor Details
#initialize(flavour) ⇒ Serializer
Returns a new instance of Serializer.
85 86 87 88 89 90 |
# File 'lib/ruote/util/serializer.rb', line 85 def initialize(flavour) @flavour = FLAVOURS[flavour] || MARSHAL64 @flavour[0].call # initializes the flavour end |
Instance Method Details
#decode(s) ⇒ Object
97 98 99 100 |
# File 'lib/ruote/util/serializer.rb', line 97 def decode(s) @flavour[2].call(s) end |
#encode(o) ⇒ Object
92 93 94 95 |
# File 'lib/ruote/util/serializer.rb', line 92 def encode(o) @flavour[1].call(o) end |