Sha256: 395ae67dbc8dbc603f2c929480cabe118171ec06070e7e11abb538b1ef876f65

Contents?: true

Size: 974 Bytes

Versions: 6

Compression:

Stored size: 974 Bytes

Contents

module Hikki
  module Adapters
    class MemcacheCollection < Hikki::Collection
      attr_reader :connection, :uuid_generator

      def initialize(collection, connection, uuid_generator)
        super(collection)
        @connection = connection
        @uuid_generator = uuid_generator
      end

      def index(field)
        false
      end

      def save(data)
        data = normalize_data(data)
        connection.set(key(data['id']), data)
        data
      end

      def find(id)
        connection.get(key(id)) || {}
      end

      def all(options={})
        []
      end

      def find_by(field, value, options={})
        []
      end

      def remove(id)
        connection.delete(key(id))
        true
      end

      def remove_all
        connection.flush
      end

      def id_for(data)
        data.fetch('id', uuid_generator.uuid).to_s
      end

      private
      def key(id)
        collection + ':' + id.to_s
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
hikki-memcache-0.0.3 lib/hikki/adapters/memcache_collection.rb
hikki-0.0.3 adapters/hikki-memcache/lib/hikki/adapters/memcache_collection.rb
hikki-memcache-0.0.2 lib/hikki/adapters/memcache_collection.rb
hikki-0.0.2 adapters/hikki-memcache/lib/hikki/adapters/memcache_collection.rb
hikki-memcache-0.0.1 lib/hikki/adapters/memcache_collection.rb
hikki-0.0.1 adapters/hikki-memcache/lib/hikki/adapters/memcache_collection.rb