Class: Cuprum::Rails::Commands::ValidateOne

Inherits:
Cuprum::Rails::Command show all
Defined in:
lib/cuprum/rails/commands/validate_one.rb

Overview

Command for validating an ActiveRecord record.

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

Validates the record against the given or default contract.

If the record matches the contract, #call will return a passing result with the record as the result value. If the record 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 record. If not given, the record will be validated using the collection’s default contract.

  • entity (ActiveRecord::Base) (defaults to: )

    The collection record to validate.

Returns:

  • (Cuprum::Result<ActiveRecord::Base>)

    the validated record.



26
27
28
29
30
31
# File 'lib/cuprum/rails/commands/validate_one.rb', line 26

validate_parameters :call do
  keyword :contract,
    Stannum::Constraints::Base,
    optional: true
  keyword :entity, Object
end