Class: Cuprum::Rails::Commands::FindOne

Inherits:
Cuprum::Rails::Command show all
Includes:
Collections::Commands::AbstractFindOne
Defined in:
lib/cuprum/rails/commands/find_one.rb

Overview

Command for finding one ActiveRecord record by primary key.

Instance Attribute Summary

Attributes inherited from Cuprum::Rails::Command

#collection_name, #member_name, #options, #record_class

Instance Method Summary collapse

Methods inherited from Cuprum::Rails::Command

#initialize, #primary_key_name, #primary_key_type, subclass

Constructor Details

This class inherits a constructor from Cuprum::Rails::Command

Instance Method Details

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

Queries the collection for the record 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 record 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 record.

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

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

Returns:

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

    a result with the requested record.



34
35
36
37
38
# File 'lib/cuprum/rails/commands/find_one.rb', line 34

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