Module: Lotus::Model::Adapters::Implementation Private
- Included in:
- MemoryAdapter, SqlAdapter
- Defined in:
- lib/lotus/model/adapters/implementation.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Shared implementation for SqlAdapter and MemoryAdapter
Instance Method Summary collapse
-
#all(collection) ⇒ Array
private
Returns all the records for the given collection.
-
#find(collection, id) ⇒ Object
private
Returns a unique record from the given collection, with the given id.
-
#first(collection) ⇒ Object
private
Returns the first record in the given collection.
-
#last(collection) ⇒ Object
private
Returns the last record in the given collection.
-
#persist(collection, entity) ⇒ Object
private
Creates or updates a record in the database for the given entity.
Instance Method Details
#all(collection) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns all the records for the given collection
34 35 36 37 |
# File 'lib/lotus/model/adapters/implementation.rb', line 34 def all(collection) # TODO consider to make this lazy (aka remove #all) query(collection).all end |
#find(collection, id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a unique record from the given collection, with the given id.
49 50 51 52 53 |
# File 'lib/lotus/model/adapters/implementation.rb', line 49 def find(collection, id) _first( _find(collection, id) ) end |
#first(collection) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the first record in the given collection.
63 64 65 66 67 |
# File 'lib/lotus/model/adapters/implementation.rb', line 63 def first(collection) _first( query(collection).asc(_identity(collection)) ) end |
#last(collection) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the last record in the given collection.
77 78 79 80 81 |
# File 'lib/lotus/model/adapters/implementation.rb', line 77 def last(collection) _first( query(collection).desc(_identity(collection)) ) end |
#persist(collection, entity) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates or updates a record in the database for the given entity.
18 19 20 21 22 23 24 |
# File 'lib/lotus/model/adapters/implementation.rb', line 18 def persist(collection, entity) if entity.id update(collection, entity) else create(collection, entity) end end |