Class: Lotus::Model::Adapters::MemoryAdapter Private

Inherits:
Abstract
  • Object
show all
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.

See Also:

Since:

  • 0.1.0

Direct Known Subclasses

FileSystemAdapter

Instance Method Summary collapse

Methods included from Implementation

#all, #find, #first, #last, #persist

Methods inherited from Abstract

#all, #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.

See Also:

Since:

  • 0.1.0



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.

Since:

  • 0.1.0



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.

Since:

  • 0.1.0



51
52
53
54
55
56
# File 'lib/lotus/model/adapters/memory_adapter.rb', line 51

def create(collection, entity)
  synchronize do
    entity.id = command(collection).create(entity)
    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.

Since:

  • 0.1.0



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

#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

See Also:

Since:

  • 0.1.0



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

#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.

Since:

  • 0.1.0



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