class Sift::TypeValidator

TypeValidator validates that the incoming param is of the specified type

Constants

BOOLEAN_PATTERN
DATETIME_RANGE_PATTERN
DECIMAL_PATTERN
JSON_PATTERN
WHITELIST_TYPES

Attributes

param[R]
type[R]

Public Class Methods

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

Public Instance Methods

valid_type?() click to toggle source
# File lib/sift/type_validator.rb, line 42
def valid_type?
  WHITELIST_TYPES.include?(type)
end
validate() click to toggle source
# File lib/sift/type_validator.rb, line 27
def validate
  case type
  when :datetime, :date, :time
    DATETIME_RANGE_PATTERN
  when :int
    valid_int?
  when :decimal
    DECIMAL_PATTERN
  when :boolean
    BOOLEAN_PATTERN
  when :jsonb
    JSON_PATTERN
  end
end

Private Instance Methods

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