Class: Lotus::Model::Adapters::MemoryAdapter Private
- Includes:
- Implementation
- Defined in:
- lib/lotus/model/adapters/memory_adapter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
In memory adapter that behaves like a SQL database. Not all the features of the SQL adapter are supported.
This adapter SHOULD be used only for development or testing purposes, because its computations are inefficient and the data is volatile.
Direct Known Subclasses
Instance Method Summary collapse
-
#clear(collection) ⇒ Object
private
Deletes all the records from the given collection and resets the identity counter.
-
#command(collection) ⇒ Lotus::Model::Adapters::Memory::Command
private
Fabricates a command for the given query.
-
#create(collection, entity) ⇒ Object
private
Creates a record in the database for the given entity.
-
#delete(collection, entity) ⇒ Object
private
Deletes a record in the database corresponding to the given entity.
-
#initialize(mapper, uri = nil) ⇒ Lotus::Model::Adapters::MemoryAdapter
constructor
private
Initialize the adapter.
-
#query(collection, context = nil, &blk) ⇒ Lotus::Model::Adapters::Memory::Query
private
Fabricates a query.
-
#transaction(options = {}) ⇒ Object
private
WARNING: this is a no-op.
-
#update(collection, entity) ⇒ Object
private
Updates a record in the database corresponding to the given entity.
Methods included from Implementation
#all, #find, #first, #last, #persist
Methods inherited from Abstract
#all, #connection_string, #execute, #find, #first, #last, #persist
Constructor Details
#initialize(mapper, uri = nil) ⇒ Lotus::Model::Adapters::MemoryAdapter
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.
Initialize the adapter.
34 35 36 37 38 39 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 34 def initialize(mapper, uri = nil) super @mutex = Mutex.new @collections = {} end |
Instance Method Details
#clear(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.
Deletes all the records from the given collection and resets the identity counter.
92 93 94 95 96 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 92 def clear(collection) synchronize do command(collection).clear end end |
#command(collection) ⇒ Lotus::Model::Adapters::Memory::Command
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.
Fabricates a command for the given query.
108 109 110 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 108 def command(collection) Memory::Command.new(_collection(collection), _mapped_collection(collection)) end |
#create(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 a record in the database for the given entity. It assigns the ‘id` attribute, in case of success.
51 52 53 54 55 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 51 def create(collection, entity) synchronize do command(collection).create(entity) end end |
#delete(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.
Deletes a record in the database corresponding to the given entity.
79 80 81 82 83 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 79 def delete(collection, entity) synchronize do command(collection).delete(entity) end end |
#query(collection, context = nil, &blk) ⇒ Lotus::Model::Adapters::Memory::Query
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.
Fabricates a query
124 125 126 127 128 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 124 def query(collection, context = nil, &blk) synchronize do Memory::Query.new(_collection(collection), _mapped_collection(collection), &blk) end end |
#transaction(options = {}) ⇒ 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.
WARNING: this is a no-op. For “real” transactions please use ‘SqlAdapter` or another adapter that supports them
139 140 141 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 139 def transaction( = {}) yield end |
#update(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.
Updates a record in the database corresponding to the given entity.
66 67 68 69 70 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 66 def update(collection, entity) synchronize do command(collection).update(entity) end end |