Class: Cuprum::Collections::Basic::Commands::ValidateOne

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

Overview

Command for validating a collection entity.

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(entity: , contract: nil) ⇒ Cuprum::Result<Hash>

Validates the entity against the given or default contract.

If the entity matches the contract, #call will return a passing result with the entity as the result value. If the entity does not match the contract, #call will return a failing result with a FailedValidation error and the validation errors.

Parameters:

  • contract (Stannum::Constraints:Base) (defaults to: nil)

    The contract with which to validate the entity. If not given, the entity will be validated using the collection’s default contract.

  • entity (Hash) (defaults to: )

    The collection entity to validate.

Returns:

  • (Cuprum::Result<Hash>)

    the validated entity.



27
28
29
30
31
32
33
# File 'lib/cuprum/collections/basic/commands/validate_one.rb', line 27

validate_parameters :call do
  keyword :contract,
    Stannum::Constraints::Base,
    optional: true
  keyword :entity,
    Stannum::Constraints::Types::HashWithStringKeys.new
end