Module: PDK::Config::Validator

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

Overview

A collection of predefined validators for use with Value.

Examples:

value :enabled do
  validate PDK::Config::Validator.boolean
end

Class Method Summary collapse

Class Method Details

.booleanHash{Symbol => [Proc,String]}

Returns a PDK::Config::Value validator that ensures that the value is either a TrueClass or FalseClass.

Returns:

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

    a PDK::Config::Value validator that ensures that the value is either a TrueClass or FalseClass.



13
14
15
16
17
18
# File 'lib/pdk/config/validator.rb', line 13

def self.boolean
  {
    proc: ->(value) { [true, false].include?(value) },
    message: 'must be a boolean: true or false'
  }
end

.uuidHash{Symbol => [Proc,String]}

Returns a PDK::Config::Value validator that ensures that the value is a String that matches the regex for a version 4 UUID.

Returns:

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

    a PDK::Config::Value validator that ensures that the value is a String that matches the regex for a version 4 UUID.



23
24
25
26
27
28
# File 'lib/pdk/config/validator.rb', line 23

def self.uuid
  {
    proc: ->(value) { value.match(/\A\h{8}(?:-\h{4}){3}-\h{12}\z/) },
    message: 'must be a version 4 UUID'
  }
end