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 30
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 58
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
Calls superclass method
# File lib/apipie_dsl/validator.rb, line 52
def self.inherited(subclass)
  super(subclass)
  @validators ||= []
  @validators.unshift(subclass)
end
new(param_description) click to toggle source
# File lib/apipie_dsl/validator.rb, line 26
def initialize(param_description)
  @param_description = param_description
end

Public Instance Methods

==(other) click to toggle source
# File lib/apipie_dsl/validator.rb, line 94
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 38
def description
  raise NotImplementedError
end
docs() click to toggle source
# File lib/apipie_dsl/validator.rb, line 76
def docs
  raise NotImplementedError
end
expected_type() click to toggle source
# File lib/apipie_dsl/validator.rb, line 80
def expected_type
  'string'
end
inspect() click to toggle source
# File lib/apipie_dsl/validator.rb, line 46
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 42
def inspected_fields
  [:param_description]
end
merge_with(other_validator) click to toggle source
# File lib/apipie_dsl/validator.rb, line 88
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 84
def sub_params
  nil
end
to_s() click to toggle source
# File lib/apipie_dsl/validator.rb, line 72
def to_s
  description
end
valid?(value) click to toggle source
# File lib/apipie_dsl/validator.rb, line 66
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 34
def validate(_value)
  raise NotImplementedError
end