Sha256: 2885b401ed71d5fc52a75a10587a7e82a4ae3859f297dd5220baad9433979ed3

Contents?: true

Size: 810 Bytes

Versions: 1

Compression:

Stored size: 810 Bytes

Contents

require 'couchbase_doc_store'

# haven't written this one yet... it's a copy of Stack code
module CouchbaseStructures
  class SortedList
    include CouchbaseDocStore

    def initialize(key, sort_type = {})

      @key = key
      @top_index_key = "#{key}::stack::top"
      initialize_document(@top_index_key, 0)
      self
    end

    def push(value)
      new_top_index = increase_atomic_count(@top_index_key)
      create_document("#{key}::stack::#{new_top_index}", value)
      self
    end

    def pop()
      old_top_index = get_document(@top_index_key)
      decrease_atomic_count(@top_index_key)

      doc = get_document("#{key}::stack::#{old_top_index}")
      delete_document("#{key}::stack::#{old_top_index}")
      doc
    end

    def size
      get_document(@top_index_key)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
couchbase-structures-0.0.2 lib/couchbase_structures/sorted_list.rb