Module: MemoryModel::Collection::Operations
- Included in:
- MemoryModel::Collection
- Defined in:
- lib/memory_model/collection/operations.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #create(item) ⇒ Object
- #delete(item) ⇒ Object
- #load_all(*uuids) ⇒ Object
- #read(key) ⇒ Object
- #read_all(*ids) ⇒ Object
- #update(item) ⇒ Object
Instance Method Details
#clear ⇒ Object
5 6 7 8 9 |
# File 'lib/memory_model/collection/operations.rb', line 5 def clear indexes.each { |name, index| index.clear } GC.start all end |
#create(item) ⇒ Object
21 22 23 24 |
# File 'lib/memory_model/collection/operations.rb', line 21 def create(item) item._uuid_ = SecureRandom.uuid transact item, operation: :create, rollback_with: :delete end |
#delete(item) ⇒ Object
34 35 36 |
# File 'lib/memory_model/collection/operations.rb', line 34 def delete(item) transact item, operation: :delete end |
#load_all(*uuids) ⇒ Object
16 17 18 19 |
# File 'lib/memory_model/collection/operations.rb', line 16 def load_all(*uuids) return [] if uuids.blank? indexes[:_uuid_].values_at(*uuids).compact.map(&:load) end |
#read(key) ⇒ Object
26 27 28 |
# File 'lib/memory_model/collection/operations.rb', line 26 def read(key) indexes[primary_key].read(key) end |
#read_all(*ids) ⇒ Object
11 12 13 14 |
# File 'lib/memory_model/collection/operations.rb', line 11 def read_all(*ids) return [] if ids.blank? indexes[primary_key].values_at(*ids).compact end |
#update(item) ⇒ Object
30 31 32 |
# File 'lib/memory_model/collection/operations.rb', line 30 def update(item) transact item, operation: :update, rollback_with: :rollback end |