class Apipie::Validator::BaseValidator
to create new validator, inherit from Apipie::Validator::Base and implement class method build and instance method validate
Attributes
param_description[RW]
Public Class Methods
find(param_description, argument, options, block)
click to toggle source
find the right validator for given options
# File lib/apipie/validator.rb, line 21 def self.find(param_description, argument, options, block) @validators.each do |validator_type| validator = validator_type.build(param_description, argument, options, block) return validator if validator end return nil end
inherited(subclass)
click to toggle source
# File lib/apipie/validator.rb, line 15 def self.inherited(subclass) @validators ||= [] @validators.insert 0, subclass end
new(param_description)
click to toggle source
# File lib/apipie/validator.rb, line 11 def initialize(param_description) @param_description = param_description end
Public Instance Methods
description()
click to toggle source
validator description
# File lib/apipie/validator.rb, line 45 def description "TODO: validator description" end
error()
click to toggle source
# File lib/apipie/validator.rb, line 49 def error ParamInvalid.new(param_name, @error_value, description) end
expected_type()
click to toggle source
what type is expected, mostly string this information is used in cli client thor supported types :string, :hash, :array, :numeric, or :boolean
# File lib/apipie/validator.rb, line 64 def expected_type 'string' end
merge_with(other_validator)
click to toggle source
# File lib/apipie/validator.rb, line 68 def merge_with(other_validator) raise NotImplementedError, "Dont know how to merge #{self.inspect} with #{other_validator.inspect}" end
param_name()
click to toggle source
# File lib/apipie/validator.rb, line 40 def param_name @param_description.name end
params_ordered()
click to toggle source
# File lib/apipie/validator.rb, line 72 def params_ordered nil end
to_json()
click to toggle source
# File lib/apipie/validator.rb, line 57 def to_json self.description end
to_s()
click to toggle source
# File lib/apipie/validator.rb, line 53 def to_s self.description end
valid?(value)
click to toggle source
check if value is valid
# File lib/apipie/validator.rb, line 30 def valid?(value) if self.validate(value) @error_value = nil true else @error_value = value false end end