Class: Lotus::Model::Adapters::Abstract
- Inherits:
-
Object
- Object
- Lotus::Model::Adapters::Abstract
- Defined in:
- lib/lotus/model/adapters/abstract.rb
Overview
Abstract adapter.
An adapter is a concrete implementation that allows a repository to communicate with a single database.
Lotus::Model is shipped with Memory and SQL adapters. Third part adapters MUST implement the interface defined here. For convenience they may inherit from this class.
These are low level details, and shouldn’t be used directly. Please use a repository for entities persistence.
Direct Known Subclasses
Instance Method Summary collapse
-
#all(collection) ⇒ Array
Returns all the records for the given collection.
-
#clear(collection) ⇒ Object
Empties the given collection.
-
#command(query) ⇒ Object
Executes a command for the given query.
-
#create(collection, entity) ⇒ Object
Creates a record in the database for the given entity.
-
#delete(collection, entity) ⇒ Object
Deletes a record in the database corresponding to the given entity.
-
#find(collection, id) ⇒ Object
Returns a unique record from the given collection, with the given identity.
-
#first(collection) ⇒ Object
Returns the first record in the given collection.
-
#initialize(mapper, uri = nil) ⇒ Abstract
constructor
Initialize the adapter.
-
#last(collection) ⇒ Object
Returns the last record in the given collection.
-
#persist(collection, entity) ⇒ Object
Creates or updates a record in the database for the given entity.
-
#query(collection, &blk) ⇒ Object
Returns a query.
-
#update(collection, entity) ⇒ Object
Updates a record in the database corresponding to the given entity.
Constructor Details
#initialize(mapper, uri = nil) ⇒ Abstract
Initialize the adapter
37 38 39 40 |
# File 'lib/lotus/model/adapters/abstract.rb', line 37 def initialize(mapper, uri = nil) @mapper = mapper @uri = uri end |
Instance Method Details
#all(collection) ⇒ Array
Returns all the records for the given collection
96 97 98 |
# File 'lib/lotus/model/adapters/abstract.rb', line 96 def all(collection) raise NotImplementedError end |
#clear(collection) ⇒ Object
Empties the given collection.
140 141 142 |
# File 'lib/lotus/model/adapters/abstract.rb', line 140 def clear(collection) raise NotImplementedError end |
#command(query) ⇒ Object
Executes a command for the given query.
149 150 151 |
# File 'lib/lotus/model/adapters/abstract.rb', line 149 def command(query) raise NotImplementedError end |
#create(collection, entity) ⇒ Object
Creates a record in the database for the given entity. It should assign an id (identity) to the entity in case of success.
63 64 65 |
# File 'lib/lotus/model/adapters/abstract.rb', line 63 def create(collection, entity) raise NotImplementedError end |
#delete(collection, entity) ⇒ Object
Deletes a record in the database corresponding to the given entity.
85 86 87 |
# File 'lib/lotus/model/adapters/abstract.rb', line 85 def delete(collection, entity) raise NotImplementedError end |
#find(collection, id) ⇒ Object
Returns a unique record from the given collection, with the given identity.
109 110 111 |
# File 'lib/lotus/model/adapters/abstract.rb', line 109 def find(collection, id) raise NotImplementedError end |
#first(collection) ⇒ Object
Returns the first record in the given collection.
120 121 122 |
# File 'lib/lotus/model/adapters/abstract.rb', line 120 def first(collection) raise NotImplementedError end |
#last(collection) ⇒ Object
Returns the last record in the given collection.
131 132 133 |
# File 'lib/lotus/model/adapters/abstract.rb', line 131 def last(collection) raise NotImplementedError end |
#persist(collection, entity) ⇒ Object
Creates or updates a record in the database for the given entity.
50 51 52 |
# File 'lib/lotus/model/adapters/abstract.rb', line 50 def persist(collection, entity) raise NotImplementedError end |
#query(collection, &blk) ⇒ Object
Returns a query
162 163 164 |
# File 'lib/lotus/model/adapters/abstract.rb', line 162 def query(collection, &blk) raise NotImplementedError end |
#update(collection, entity) ⇒ Object
Updates a record in the database corresponding to the given entity.
75 76 77 |
# File 'lib/lotus/model/adapters/abstract.rb', line 75 def update(collection, entity) raise NotImplementedError end |