Class: Lotus::Model::Adapters::Abstract

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

Since:

  • 0.1.0

Direct Known Subclasses

MemoryAdapter, SqlAdapter

Instance Method Summary collapse

Constructor Details

#initialize(mapper, uri = nil) ⇒ Abstract

Initialize the adapter

Since:

  • 0.1.0



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

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



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.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



75
76
77
# File 'lib/lotus/model/adapters/abstract.rb', line 75

def update(collection, entity)
  raise NotImplementedError
end