Class: Lotus::Model::Adapters::Dynamodb::Command Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/model/adapters/dynamodb/command.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.

Execute a command for the given collection.

See Also:

Since:

  • 0.1.0

API:

  • private

Instance Method Summary collapse

Constructor Details

#initialize(dataset, collection) ⇒ Lotus::Model::Adapters::Dynamodb::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.

Initialize a command.

Parameters:

Since:

  • 0.1.0

API:

  • private



22
23
24
# File 'lib/lotus/model/adapters/dynamodb/command.rb', line 22

def initialize(dataset, collection)
  @dataset, @collection = dataset, collection
end

Instance Method Details

#_serialize(entity) ⇒ Hash (private)

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.

Serialize the given entity before to persist in the database.

Parameters:

  • the entity

Returns:

  • the serialized entity

Since:

  • 0.1.0

API:

  • private



96
97
98
# File 'lib/lotus/model/adapters/dynamodb/command.rb', line 96

def _serialize(entity)
  @collection.serialize(entity)
end

#create(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 for the given entity.

Parameters:

  • the entity to persist

Returns:

  • the primary key of the just created record.

See Also:

Since:

  • 0.1.0

API:

  • private



36
37
38
39
40
# File 'lib/lotus/model/adapters/dynamodb/command.rb', line 36

def create(entity)
  @dataset.create(
    _serialize(entity)
  )
end

#delete(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 the corresponding record for the given entity.

Parameters:

  • the entity to delete

See Also:

Since:

  • 0.1.0

API:

  • private



64
65
66
67
68
# File 'lib/lotus/model/adapters/dynamodb/command.rb', line 64

def delete(entity)
  @dataset.delete(
    _serialize(entity)
  )
end

#get(key) ⇒ 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 an unique record from the given collection, with the given id.

Parameters:

  • the identity of the object

Returns:

  • the entity

See Also:

Since:

  • 0.1.0

API:

  • private



81
82
83
84
85
# File 'lib/lotus/model/adapters/dynamodb/command.rb', line 81

def get(key)
  @collection.deserialize(
    [@dataset.get(key)].compact
  ).first
end

#update(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 the corresponding record for the given entity.

Parameters:

  • the entity to persist

See Also:

Since:

  • 0.1.0

API:

  • private



50
51
52
53
54
# File 'lib/lotus/model/adapters/dynamodb/command.rb', line 50

def update(entity)
  @dataset.update(
    _serialize(entity)
  )
end