Sha256: a3371efbb875ad0614479742ba73f97e8dab22a219a0fa73373279b3d0707c38

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Daybreak
  module Serializer
    # Default serializer which converts
    # keys to strings and marshalls values
    # @api public
    class Default
      # Transform the key to a string
      # @param [Object] key
      # @return [String] key transformed to string
      def key_for(key)
        key.to_s
      end

      # Serialize a value
      # @param [Object] value
      # @return [String] value transformed to string
      def dump(value)
        Marshal.dump(value)
      end

      # Parse a value
      # @param [String] value
      # @return [Object] deserialized value
      def load(value)
        Marshal.load(value)
      end
    end

    # Serializer which does nothing
    # @api public
    class None
      # (see Daybreak::Serializer::Default#key_for)
      def key_for(key)
        key
      end

      # (see Daybreak::Serializer::Default#dump)
      def dump(value)
        value
      end

      # (see Daybreak::Serializer::Default#load)
      def load(value)
        value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
daybreak-0.2.2 lib/daybreak/serializer.rb