Module: Dragonfly::Serializer
- Defined in:
- lib/dragonfly/serializer.rb
Defined Under Namespace
Classes: BadString
Instance Method Summary collapse
- #b64_decode(string) ⇒ Object
- #b64_encode(string) ⇒ Object
- #marshal_decode(string) ⇒ Object
- #marshal_encode(object) ⇒ Object
Instance Method Details
#b64_decode(string) ⇒ Object
16 17 18 19 |
# File 'lib/dragonfly/serializer.rb', line 16 def b64_decode(string) padding_length = string.length % 4 Base64.decode64(string + '=' * padding_length) end |
#b64_encode(string) ⇒ Object
12 13 14 |
# File 'lib/dragonfly/serializer.rb', line 12 def b64_encode(string) Base64.encode64(string).tr("\n=",'') end |
#marshal_decode(string) ⇒ Object
25 26 27 28 29 |
# File 'lib/dragonfly/serializer.rb', line 25 def marshal_decode(string) Marshal.load(b64_decode(string)) rescue TypeError, ArgumentError => e raise BadString, "couldn't decode #{string} - got #{e}" end |
#marshal_encode(object) ⇒ Object
21 22 23 |
# File 'lib/dragonfly/serializer.rb', line 21 def marshal_encode(object) b64_encode(Marshal.dump(object)) end |