Class: Cuprum::Collections::Basic::Commands::AssignOne

Inherits:
Cuprum::Collections::Basic::Command show all
Defined in:
lib/cuprum/collections/basic/commands/assign_one.rb

Overview

Command for assigning attributes to a collection entity.

Instance Attribute Summary

Attributes inherited from CollectionCommand

#collection

Instance Method Summary collapse

Methods inherited from Cuprum::Collections::Basic::Command

#data, #default_contract

Methods inherited from CollectionCommand

#initialize, #name, #primary_key_name, #primary_key_type, #query, #singular_name

Constructor Details

This class inherits a constructor from Cuprum::Collections::CollectionCommand

Instance Method Details

#call(attributes:, entity:) ⇒ Hash

Assigns the given attributes to the entity.

Any attributes on the entity that are not part of the given attributes hash are unchanged.

Examples:

Assigning attributes

entity = {
  'title'    => 'The Hobbit',
  'author'   => 'J.R.R. Tolkien',
  'series'   => nil,
  'category' => 'Science Fiction and Fantasy'
}
attributes = { title: 'The Silmarillion' }
command = AssignOne.new(collection_name: 'books', data: books)
command.call(attributes: attributes, entity: entity)
#=> {
  'title'    => 'The Silmarillion',
  'author'   => 'J.R.R. Tolkien',
  'series'   => nil,
  'category' => 'Science Fiction and Fantasy'
}

Parameters:

  • attributes (Hash)

    The attributes and values to update.

  • entity (Hash)

    The collection entity to update.

Returns:

  • (Hash)

    a copy of the entity, merged with the given attributes.



39
# File 'lib/cuprum/collections/basic/commands/assign_one.rb', line 39

validate :attributes