Sha256: 5a7d6306d4a3d9075dbde07a0ee56233f6ae1660a06c7dc1996913f758f0ba1d

Contents?: true

Size: 961 Bytes

Versions: 2

Compression:

Stored size: 961 Bytes

Contents

module PDK
  class Config
    # A collection of predefined validators for use with {PDK::Config::Value}.
    #
    # @example
    #   value :enabled do
    #     validate PDK::Config::Validator.boolean
    #   end
    module Validator
      # @return [Hash{Symbol => [Proc,String]}] a {PDK::Config::Value}
      #   validator that ensures that the value is either a TrueClass or
      #   FalseClass.
      def self.boolean
        {
          proc:    ->(value) { [true, false].include?(value) },
          message: _('must be a boolean true or false'),
        }
      end

      # @return [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.
      def self.uuid
        {
          proc:    ->(value) { value.match(%r{\A\h{8}(?:-\h{4}){3}-\h{12}\z}) },
          message: _('must be a version 4 UUID'),
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pdk-1.11.1 lib/pdk/config/validator.rb
pdk-1.11.0 lib/pdk/config/validator.rb