class ApipieDSL::Validator::TypeValidator

Public Class Methods

build(param_description, argument, _options, block) click to toggle source
# File lib/apipie_dsl/validator.rb, line 107
def self.build(param_description, argument, _options, block)
  return unless argument.is_a?(::Class)
  return if argument == Hash && !block.nil?

  new(param_description, argument)
end
new(param_description, argument) click to toggle source
# File lib/apipie_dsl/validator.rb, line 102
def initialize(param_description, argument)
  super(param_description)
  @type = argument
end

Public Instance Methods

description() click to toggle source
# File lib/apipie_dsl/validator.rb, line 120
def description
  "Must be a #{@type}"
end
expected_type() click to toggle source
# File lib/apipie_dsl/validator.rb, line 124
def expected_type
  if @type.ancestors.include?(Hash)
    'hash'
  elsif @type.ancestors.include?(Array)
    'array'
  elsif @type.ancestors.include?(Numeric)
    'numeric'
  else
    'string'
  end
end
validate(value) click to toggle source
# File lib/apipie_dsl/validator.rb, line 114
def validate(value)
  return false if value.nil?

  value.is_a?(@type)
end