Method: PDK::Config::Setting#validate

Defined in:
lib/pdk/config/setting.rb

#validate(validator) ⇒ nil

Assign a validator to the setting. Subclasses should not override this method.

Parameters:

  • validator (Hash{Symbol => [Proc,String]})

Options Hash (validator):

  • :proc (Proc)

    a lambda that takes the setting to be validated as the argument and returns ‘true` if the setting is valid.

  • :message (String)

    a description of what the validator is testing for, that is displayed to the user as part of the error message for invalid settings.

Returns:

  • (nil)

Raises:

  • (ArgumentError)

    if not passed a Hash.

  • (ArgumentError)

    if the Hash doesn’t have a ‘:proc` key that contains a Proc.

  • (ArgumentError)

    if the Hash doesn’t have a ‘:message` key that contains a String.



79
80
81
82
83
84
85
# File 'lib/pdk/config/setting.rb', line 79

def validate(validator)
  raise ArgumentError, '`validator` must be a Hash' unless validator.is_a?(Hash)
  raise ArgumentError, 'the :proc key must contain a Proc' unless validator.key?(:proc) && validator[:proc].is_a?(Proc)
  raise ArgumentError, 'the :message key must contain a String' unless validator.key?(:message) && validator[:message].is_a?(String)

  @validators << validator
end