Class: Cuprum::Collections::Basic::Commands::FindOne

Inherits:
Cuprum::Collections::Basic::Command show all
Includes:
Commands::AbstractFindOne
Defined in:
lib/cuprum/collections/basic/commands/find_one.rb

Overview

Command for finding one collection item by primary key.

Instance Attribute Summary

Attributes inherited from Cuprum::Collections::Basic::Command

#collection_name, #data, #default_contract, #member_name, #options, #primary_key_name, #primary_key_type

Instance Method Summary collapse

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

#initialize, subclass

Constructor Details

This class inherits a constructor from Cuprum::Collections::Basic::Command

Instance Method Details

#call(primary_key: , envelope: false, scope: nil) ⇒ Cuprum::Result<Hash{String, Object}>

Queries the collection for the item with the given primary key.

The command will find and return the entity with the given primary key. If the entity is not found, the command will fail and return a NotFound error.

When the :envelope option is true, the command wraps the item in a Hash, using the singular name of the collection as the key.

Parameters:

  • envelope (Boolean) (defaults to: false)

    If true, wraps the result value in a Hash.

  • primary_key (Object) (defaults to: )

    The primary key of the requested item.

  • scope (Cuprum::Collections::Basic::Query, nil) (defaults to: nil)

    Optional scope for the query. The item must match the scope as well as the primary key.

Returns:

  • (Cuprum::Result<Hash{String, Object}>)

    a result with the requested item.



31
32
33
34
35
# File 'lib/cuprum/collections/basic/commands/find_one.rb', line 31

validate_parameters :call do
  keyword :envelope,    Stannum::Constraints::Boolean.new, default: true
  keyword :primary_key, Object
  keyword :scope,       Cuprum::Collections::Basic::Query, optional: true
end