class Brita::TypeValidator

TypeValidator validates that the incoming param is of the specified type

Constants

BOOLEAN_PATTERN
DECIMAL_PATTERN
RANGE_PATTERN
WHITELIST_TYPES

Attributes

param[R]
type[R]

Public Class Methods

new(param, type) click to toggle source
# File lib/brita/type_validator.rb, line 18
def initialize(param, type)
  @param = param
  @type = type
end

Public Instance Methods

valid_type?() click to toggle source
# File lib/brita/type_validator.rb, line 38
def valid_type?
  WHITELIST_TYPES.include?(type)
end
validate() click to toggle source
# File lib/brita/type_validator.rb, line 25
def validate
  case type
  when :datetime, :date, :time
    RANGE_PATTERN
  when :int
    valid_int?
  when :decimal
    DECIMAL_PATTERN
  when :boolean
    BOOLEAN_PATTERN
  end
end

Private Instance Methods

valid_int?() click to toggle source
# File lib/brita/type_validator.rb, line 44
def valid_int?
  { valid_int: true }
end