Cuprum

An opinionated implementation of the Command pattern for Ruby applications. Cuprum wraps your business logic in a consistent, object-oriented interface and features status and error management, composability and control flow management.

Module: Cuprum::ParameterValidation::ClassMethods

Parent Namespace
Cuprum::ParameterValidation
Defined In
lib/cuprum/parameter_validation.rb

Table Of Contents

Overview

Class methods for parameter validation.

Back To Top

Instance Methods

#validate(name, **options) =>
#validate(name, using:, **options) =>
#validate(name, **options, &block) =>
#validate(name, type, **options) => Object

Overloads

#validate(name, **options) =>

Defines a validation for the specified parameter.

This validation will call the #validate_$name method on the command with the value of the named parameter. If the method returns a failure message, that message is added to the failed validations.

Parameters
  • name (String, Symbol) — the parameter to validate.
  • options (Hash) — additional options to pass to the validation method.
Options Hash (options)
  • as (String, Symbol) — the name of the parameter as displayed in the failure message, if any. Defaults to the value of the name parameter.
Returns
  • () — void
#validate(name, using:, **options) =>

Defines a validation for the specified parameter.

This validation will call the named method on the command with the value of the named parameter. If the method returns a failure message, that message is added to the failed validations.

Parameters
  • name (String, Symbol) — the parameter to validate.
  • using (String, Symbol) — the name of the method used to validate the parameter.
  • options (Hash) — additional options to pass to the validation method.
Options Hash (options)
  • as (String, Symbol) — the name of the parameter as displayed in the failure message, if any. Defaults to the value of the name parameter.
Returns
  • () — void
#validate(name, **options, &block) =>

Defines a validation for the specified parameter.

This validation will call the given block with the value of the named parameter. If the block returns nil or false, a failure message is added to the failed validations

Parameters
  • name (String, Symbol) — the parameter to validate.
  • options (Hash) — additional options for the validation.
Options Hash (options)
  • as (String, Symbol) — the name of the parameter as displayed in the failure message, if any. Defaults to the value of the name parameter.
  • message (String) — the failure message to display. Defaults to "$name is invalid".
Yields
  • the block to validate the parameter.
Yield Parameters
  • value (Object) — the value of the named parameter.
Yield Returns
  • (true, false) — true if the given value is valid for the parameter; otherwise false.
Returns
  • () — void
#validate(name, type, **options) => Object

Defines a validation for the specified parameter.

This validation will call the #validate_$type method on the command with the value of the named parameter. If the method returns a failure message, that message is added to the failed validations.

If the command does not define the method, it will call the SleepingKingStudios::Tools::Assertions instance method with the same name. If the validation fails, the failure message is added to the failed validations.

Parameters
  • name (String, Symbol) — the parameter to validate.
  • type (String, Symbol) — the validation method to run.
  • options (Hash) — additional options to pass to the validation method.
Options Hash (options)
  • as (String, Symbol) — the name of the parameter as displayed in the failure message, if any. Defaults to the value of the name parameter.
  • message (String) — the message to display on a failed validation.
Raises

Back To Top


Back to Documentation | Reference | Cuprum | Cuprum::ParameterValidation