class ApipieDSL::Validator::BaseValidator

To create a new validator, inherit from ApipieDSL::Validator::BaseValidator and implement class method 'build' and instance method 'validate'

Attributes

param_description[R]

Public Class Methods

build(_param_description, _argument, _options, &_block) click to toggle source
# File lib/apipie_dsl/validator.rb, line 28
def self.build(_param_description, _argument, _options, &_block)
  raise NotImplementedError
end
find(param_description, argument, options, block) click to toggle source
# File lib/apipie_dsl/validator.rb, line 55
def self.find(param_description, argument, options, block)
  @validators.each do |type|
    validator = type.build(param_description, argument, options, block)
    return validator if validator
  end
  nil
end
inherited(subclass) click to toggle source
# File lib/apipie_dsl/validator.rb, line 50
def self.inherited(subclass)
  @validators ||= []
  @validators.unshift(subclass)
end
new(param_description) click to toggle source
# File lib/apipie_dsl/validator.rb, line 24
def initialize(param_description)
  @param_description = param_description
end

Public Instance Methods

==(other) click to toggle source
# File lib/apipie_dsl/validator.rb, line 91
def ==(other)
  return false unless self.class == other.class

  param_description == other.param_description
end
description() click to toggle source
# File lib/apipie_dsl/validator.rb, line 36
def description
  raise NotImplementedError
end
docs() click to toggle source
# File lib/apipie_dsl/validator.rb, line 73
def docs
  raise NotImplementedError
end
expected_type() click to toggle source
# File lib/apipie_dsl/validator.rb, line 77
def expected_type
  'string'
end
inspect() click to toggle source
# File lib/apipie_dsl/validator.rb, line 44
def inspect
  string = "#<#{self.class.name}:#{object_id} "
  fields = inspected_fields.map { |field| "#{field}: #{send(field)}" }
  string << fields.join(', ') << '>'
end
inspected_fields() click to toggle source
# File lib/apipie_dsl/validator.rb, line 40
def inspected_fields
  [:param_description]
end
merge_with(other_validator) click to toggle source
# File lib/apipie_dsl/validator.rb, line 85
def merge_with(other_validator)
  return self if self == other_validator

  raise NotImplementedError, "Don't know how to merge #{inspect} with #{other_validator.inspect}"
end
sub_params() click to toggle source
# File lib/apipie_dsl/validator.rb, line 81
def sub_params
  nil
end
to_s() click to toggle source
# File lib/apipie_dsl/validator.rb, line 69
def to_s
  description
end
valid?(value) click to toggle source
# File lib/apipie_dsl/validator.rb, line 63
def valid?(value)
  return true if validate(value)

  raise ParamInvalid.new(@param_description.name, value, description)
end
validate(_value) click to toggle source
# File lib/apipie_dsl/validator.rb, line 32
def validate(_value)
  raise NotImplementedError
end