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.
- #disconnect ⇒ Object private
-
#initialize(mapper, uri = nil, options = {}) ⇒ 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, #fetch, #find, #first, #last, #persist
Constructor Details
#initialize(mapper, uri = nil, options = {}) ⇒ 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.
35 36 37 38 39 40 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 35 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.
93 94 95 96 97 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 93 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.
109 110 111 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 109 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.
52 53 54 55 56 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 52 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.
80 81 82 83 84 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 80 def delete(collection, entity) synchronize do command(collection).delete(entity) end end |
#disconnect ⇒ 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.
148 149 150 151 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 148 def disconnect @collections = DisconnectedResource.new @mutex = DisconnectedResource.new 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
125 126 127 128 129 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 125 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
140 141 142 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 140 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.
67 68 69 70 71 |
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 67 def update(collection, entity) synchronize do command(collection).update(entity) end end |