Class: Eternity::CollectionIndex
- Inherits:
-
Object
- Object
- Eternity::CollectionIndex
- Extended by:
- Forwardable
- Defined in:
- lib/eternity/collection_index.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #collection_name ⇒ Object
- #delete(id) ⇒ Object
- #ids ⇒ Object
- #include?(id) ⇒ Boolean
-
#initialize(options) ⇒ CollectionIndex
constructor
A new instance of CollectionIndex.
- #insert(id, data) ⇒ Object
- #update(id, data) ⇒ Object
Constructor Details
#initialize(options) ⇒ CollectionIndex
Returns a new instance of CollectionIndex.
7 8 9 |
# File 'lib/eternity/collection_index.rb', line 7 def initialize() @index = Restruct::Hash.new end |
Instance Method Details
#[](id) ⇒ Object
19 20 21 |
# File 'lib/eternity/collection_index.rb', line 19 def [](id) include?(id) ? Blob.new(:data, index[id]) : nil end |
#collection_name ⇒ Object
11 12 13 |
# File 'lib/eternity/collection_index.rb', line 11 def collection_name index.id.sections.last end |
#delete(id) ⇒ Object
33 34 35 36 |
# File 'lib/eternity/collection_index.rb', line 33 def delete(id) raise "#{collection_name.capitalize} #{id} not found" unless index.key? id index.delete id end |
#ids ⇒ Object
38 39 40 |
# File 'lib/eternity/collection_index.rb', line 38 def ids index.keys end |
#include?(id) ⇒ Boolean
15 16 17 |
# File 'lib/eternity/collection_index.rb', line 15 def include?(id) index.key? id end |