Class: Cliqr::Config::Validation::ValidationSet Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cliqr/config/validation/validation_set.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A collection of configured validators

Instance Method Summary collapse

Constructor Details

#initializeValidationSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new instance of validation set



13
14
15
# File 'lib/cliqr/config/validation/validation_set.rb', line 13

def initialize
  @set = {}
end

Instance Method Details

#add(name, options) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add a new validator

Parameters:

  • name (Symbol)

    Name of the validator

  • options (Object)

    Configuration option to initialize the validator

Returns:

  • (Hash)

    A map of all validators



23
24
25
26
# File 'lib/cliqr/config/validation/validation_set.rb', line 23

def add(name, options)
  @set[name] = \
    Hash[options.map { |type, config| [type, ValidatorFactory.get(type, config)] }]
end

#each(&block) ⇒ Cliqr::Config::Validation::ValidatorFactory::Validator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Iterate over each validators



47
48
49
# File 'lib/cliqr/config/validation/validation_set.rb', line 47

def each(&block)
  @set.each(&block)
end

#each_key(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Iterate over each type of validators

Returns:

  • (Object)


40
41
42
# File 'lib/cliqr/config/validation/validation_set.rb', line 40

def each_key(&block)
  @set.each_key(&block)
end

#merge(other) ⇒ Cliqr::Config::Validation::ValidationSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Merge validations form another set



33
34
35
# File 'lib/cliqr/config/validation/validation_set.rb', line 33

def merge(other)
  other.each { |name, validations| @set[name] = validations }
end

#validate(attribute, value, errors) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run the validators for a attribute against its value

Parameters:

  • attribute (Symbol)

    Name of the attribute

  • value (Object)

    Value of the attribute

  • errors (Cliqr::ValidationErrors)

    A collection wrapper for all validation errors

Returns:

  • (Array)

    All validators that ran for the attribute against the value



58
59
60
61
62
# File 'lib/cliqr/config/validation/validation_set.rb', line 58

def validate(attribute, value, errors)
  @set[attribute].values.each do |validator|
    validator.validate(attribute, value, errors)
  end
end