# File lib/dragonfly/serializer.rb, line 17 def b64_decode(string) padding_length = string.length % 4 string = string.tr('~', '/') Base64.decode64(string + '=' * padding_length) end
# File lib/dragonfly/serializer.rb, line 13 def b64_encode(string) Base64.encode64(string).tr("\n=",'') end
# File lib/dragonfly/serializer.rb, line 39 def json_decode(string, opts={}) MultiJson.decode(b64_decode(string), :symbolize_keys => opts[:symbolize_keys]) rescue MultiJson::DecodeError => e raise BadString, "couldn't decode #{string} - got #{e}" end
# File lib/dragonfly/serializer.rb, line 35 def json_encode(object) b64_encode(MultiJson.encode(object)) end
# File lib/dragonfly/serializer.rb, line 27 def marshal_decode(string) marshal_string = b64_decode(string) raise MaliciousString, "potentially malicious marshal string #{marshal_string.inspect}" if marshal_string[/@[a-z_]/] Marshal.load(marshal_string) rescue TypeError, ArgumentError => e raise BadString, "couldn't decode #{string} - got #{e}" end
Generated with the Darkfish Rdoc Generator 2.