Class: Lotus::Model::Adapters::FileSystemAdapter Private
- Inherits:
-
MemoryAdapter
- Object
- Abstract
- MemoryAdapter
- Lotus::Model::Adapters::FileSystemAdapter
- Defined in:
- lib/lotus/model/adapters/file_system_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 with file system persistence. It behaves like the SQL adapter, but it doesn’t support all the SQL features offered by that kind of databases.
This adapter SHOULD be used only for development or testing purposes. Each read/write operation is wrapped by a ‘Mutex` and persisted to the disk.
For those reasons it’s really unefficient, but great for quick prototyping as it’s schema-less.
It works exactly like the ‘MemoryAdapter`, with the only difference that it persist data to the disk.
The persistence policy uses Ruby ‘Marshal` `dump` and `load` operations. Please be aware of the limitations this model.
Constant Summary collapse
- WRITING_MODE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default writing mode
Binary, write only, create file if missing or erase if don’t.
File::WRONLY|File::BINARY|File::CREAT
- CHMOD =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default chmod
0644
- FILE_SCHEME =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
File scheme
'file:///'.freeze
Instance Method Summary collapse
-
#all(collection) ⇒ Array
private
Returns all the records for the given collection.
-
#clear(collection) ⇒ Object
private
Deletes all the records from the given collection and resets the identity counter.
-
#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
-
#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.
-
#info ⇒ Hash
private
Database informations.
-
#initialize(mapper, uri, options = {}) ⇒ Lotus::Model::Adapters::FileSystemAdapter
constructor
private
Initialize the adapter.
-
#last(collection) ⇒ Object
private
Returns the last record in the given collection.
-
#query(collection, context = nil, &blk) ⇒ Lotus::Model::Adapters::Memory::Query
private
Fabricates a query.
-
#update(collection, entity) ⇒ Object
private
Updates a record in the database corresponding to the given entity.
Methods inherited from MemoryAdapter
Methods included from Implementation
Methods inherited from Abstract
#command, #connection_string, #execute, #fetch, #persist, #transaction
Constructor Details
#initialize(mapper, uri, options = {}) ⇒ Lotus::Model::Adapters::FileSystemAdapter
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.
70 71 72 73 74 75 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 70 def initialize(mapper, uri, = {}) super prepare(uri) @_mutex = Mutex.new end |
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
85 86 87 88 89 90 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 85 def all(collection) _synchronize do read(collection) super end end |
#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.
191 192 193 194 195 196 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 191 def clear(collection) _synchronize do super write(collection) end 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.
149 150 151 152 153 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 149 def create(collection, entity) _synchronize do super.tap { write(collection) } 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.
177 178 179 180 181 182 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 177 def delete(collection, entity) _synchronize do super write(collection) 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.
233 234 235 236 237 238 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 233 def disconnect super @_mutex = DisconnectedResource.new @root = DisconnectedResource.new 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.
102 103 104 105 106 107 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 102 def find(collection, id) _synchronize do read(collection) super end 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.
117 118 119 120 121 122 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 117 def first(collection) _synchronize do read(collection) super end end |
#info ⇒ Hash
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.
Database informations
223 224 225 226 227 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 223 def info @collections.each_with_object({}) do |(collection,_), result| result[collection] = query(collection).count end 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.
132 133 134 135 136 137 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 132 def last(collection) _synchronize do read(collection) super 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
210 211 212 213 214 215 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 210 def query(collection, context = nil, &blk) # _synchronize do read(collection) super # end 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.
164 165 166 167 168 |
# File 'lib/lotus/model/adapters/file_system_adapter.rb', line 164 def update(collection, entity) _synchronize do super.tap { write(collection) } end end |