class Cuprum::Collections::Basic::Commands::ValidateOne
Command
for validating a collection entity.
Private Instance Methods
contract_or_default(contract:, entity:)
click to toggle source
# File lib/cuprum/collections/basic/commands/validate_one.rb, line 37 def contract_or_default(contract:, entity:) return contract if contract return default_contract if default_contract error = Cuprum::Collections::Errors::MissingDefaultContract.new( entity_class: entity.class ) failure(error) end
process(entity:, contract: nil)
click to toggle source
# File lib/cuprum/collections/basic/commands/validate_one.rb, line 48 def process(entity:, contract: nil) contract = step { contract_or_default(contract: contract, entity: entity) } step { validate_entity(contract: contract, entity: entity) } entity end
validate_entity(contract:, entity:)
click to toggle source
# File lib/cuprum/collections/basic/commands/validate_one.rb, line 57 def validate_entity(contract:, entity:) valid, errors = contract.match(entity) return if valid error = Cuprum::Collections::Errors::FailedValidation.new( entity_class: entity.class, errors: errors ) failure(error) end