Sha256: 1e20a89196572065a9743aed5d1ad37c9ddf4d0110e29d8dc3a373fc63de5b5a

Contents?: true

Size: 724 Bytes

Versions: 53

Compression:

Stored size: 724 Bytes

Contents

# encoding: utf-8
require 'base64'

module Dragonfly
  module Serializer
    
    # Exceptions
    class BadString < RuntimeError; end
    
    extend self # So we can do Serializer.b64_encode, etc.
    
    def b64_encode(string)
      Base64.encode64(string).tr("\n=",'').tr('/','~')
    end
    
    def b64_decode(string)
      padding_length = string.length % 4
      Base64.decode64(string.tr('~','/') + '=' * padding_length)
    end
    
    def marshal_encode(object)
      b64_encode(Marshal.dump(object))
    end
    
    def marshal_decode(string)
      Marshal.load(b64_decode(string))
    rescue TypeError, ArgumentError => e
      raise BadString, "couldn't decode #{string} - got #{e}"
    end
    
  end
end

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.7.4 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.7.3 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.7.2 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.7.1 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.7.0 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.9 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.8 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.7 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.6 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.5 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.4 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.3 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.2 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.1 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.6.0 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.5.17 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.5.16 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.5.15 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb
classiccms-0.5.14 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/serializer.rb