Module: Cliqr::Config::Validation Private

Included in:
Base
Defined in:
lib/cliqr/config/validation/verifiable.rb,
lib/cliqr/config/validation/validation_set.rb,
lib/cliqr/config/validation/validator_factory.rb

Overview

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

Validation framework for the command line interface config definition adopted from lotus/validations by @jodosha

Defined Under Namespace

Modules: ValidatorFactory, Verifiable Classes: ValidationSet

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ 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.

If a class includes this module, we add a few useful methods to that class



21
22
23
24
25
# File 'lib/cliqr/config/validation/verifiable.rb', line 21

def self.included(base)
  base.class_eval do
    extend Verifiable
  end
end

Instance Method Details

#errorsCliqr::ValidationErrors

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.

Get a list of errors after validation finishes

Returns:



66
67
68
# File 'lib/cliqr/config/validation/verifiable.rb', line 66

def errors
  @errors ||= ValidationErrors.new
end

#read_attributesHash

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.

Read current values for all attributes that must be validated

Returns:

  • (Hash)

    All attributes that must be validated along with their current values



55
56
57
58
59
60
61
# File 'lib/cliqr/config/validation/verifiable.rb', line 55

def read_attributes
  {}.tap do |attributes|
    validations.each_key do |attribute|
      attributes[attribute] = public_send(attribute)
    end
  end
end

#valid?Boolean

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.

Check if the class is valid based on the configured attribute validations

Returns:

  • (Boolean)

    true if there are no validation errors



30
31
32
33
34
# File 'lib/cliqr/config/validation/verifiable.rb', line 30

def valid?
  validate

  errors.empty?
end

#validateHash

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 validation against all attribute values

Returns:

  • (Hash)

    All validated attributed attributes and their values



39
40
41
42
43
# File 'lib/cliqr/config/validation/verifiable.rb', line 39

def validate
  read_attributes.each do |name, value|
    validations.validate(name, value, errors)
  end
end

#validationsHash

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.

Get the list of validations to be performed

Returns:

  • (Hash)

    A hash of attribute name to its validator



48
49
50
# File 'lib/cliqr/config/validation/verifiable.rb', line 48

def validations
  self.class.__send__(:validations)
end