Module: Lotus::Model::Adapters::Implementation Private

Included in:
MemoryAdapter, SqlAdapter
Defined in:
lib/lotus/model/adapters/implementation.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Shared implementation for SqlAdapter and MemoryAdapter

Since:

  • 0.1.0

Instance Method Summary collapse

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

Parameters:

  • collection (Symbol)

    the target collection (it must be mapped).

Returns:

  • (Array)

    all the records

Since:

  • 0.1.0



34
35
36
37
# File 'lib/lotus/model/adapters/implementation.rb', line 34

def all(collection)
  # TODO consider to make this lazy (aka remove #all)
  query(collection).all
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.

Parameters:

  • collection (Symbol)

    the target collection (it must be mapped).

  • id (Object)

    the identity of the object.

Returns:

  • (Object)

    the entity

Since:

  • 0.1.0



49
50
51
52
53
# File 'lib/lotus/model/adapters/implementation.rb', line 49

def find(collection, id)
  _first(
    _find(collection, id)
  )
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.

Parameters:

  • collection (Symbol)

    the target collection (it must be mapped).

Returns:

  • (Object)

    the first entity

Since:

  • 0.1.0



63
64
65
66
67
# File 'lib/lotus/model/adapters/implementation.rb', line 63

def first(collection)
  _first(
    query(collection).asc(_identity(collection))
  )
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.

Parameters:

  • collection (Symbol)

    the target collection (it must be mapped).

Returns:

  • (Object)

    the last entity

Since:

  • 0.1.0



77
78
79
80
81
# File 'lib/lotus/model/adapters/implementation.rb', line 77

def last(collection)
  _first(
    query(collection).desc(_identity(collection))
  )
end

#persist(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 or updates a record in the database for the given entity.

Parameters:

  • collection (Symbol)

    the target collection (it must be mapped).

  • entity (#id, #id=)

    the entity to persist

Returns:

  • (Object)

    the entity

Since:

  • 0.1.0



18
19
20
21
22
23
24
# File 'lib/lotus/model/adapters/implementation.rb', line 18

def persist(collection, entity)
  if entity.id
    update(collection, entity)
  else
    create(collection, entity)
  end
end