Sha256: 81c5429b4bf5543a10eee82f1d1361a3ed2c7f158bdfe22873f8b1db18faa2aa
Contents?: true
Size: 954 Bytes
Versions: 17
Compression:
Stored size: 954 Bytes
Contents
module Eternity class CollectionIndex extend Forwardable def_delegators :index, :to_h, :to_primitive, :empty?, :dump, :restore, :destroy, :count def initialize(options) @index = Restruct::Hash.new options end def collection_name index.id.sections.last end def include?(id) index.key? id end def [](id) include?(id) ? Blob.new(:data, index[id]) : nil end def insert(id, data) raise "#{collection_name.capitalize} #{id} already exists" if index.key? id index[id] = Blob.write :data, data end def update(id, data) raise "#{collection_name.capitalize} #{id} not found" unless index.key? id index[id] = Blob.write :data, data end def delete(id) raise "#{collection_name.capitalize} #{id} not found" unless index.key? id index.delete id end def ids index.keys end private attr_reader :index end end
Version data entries
17 entries across 17 versions & 1 rubygems