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

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



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:

  • entity (Object)

    the entity

Returns:

  • (Hash)

    the serialized entity

Since:

  • 0.1.0



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

def _serialize(entity)
  serialized = @collection.serialize(entity)
  serialized.delete_if { |_, v| v.nil? }
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:

  • entity (Object)

    the entity to persist

Returns:

  • the primary key of the just created record.

See Also:

Since:

  • 0.1.0



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:

  • entity (Object)

    the entity to delete

See Also:

Since:

  • 0.1.0



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:

  • key (Array)

    the identity of the object

Returns:

  • (Object)

    the entity

See Also:

Since:

  • 0.1.0



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:

  • entity (Object)

    the entity to persist

See Also:

Since:

  • 0.1.0



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

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