class Apipie::Validator::BaseValidator
to create new validator, inherit from Apipie::Validator::BaseValidator
and implement class method build and instance method validate
Attributes
Public Class Methods
Source
# File lib/apipie/validator.rb, line 32 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
find the right validator for given options
Source
# File lib/apipie/validator.rb, line 26 def self.inherited(subclass) @validators ||= [] @validators.insert 0, subclass end
Source
# File lib/apipie/validator.rb, line 12 def initialize(param_description) @param_description = param_description end
Source
# File lib/apipie/validator.rb, line 40 def self.raise_if_missing_params missing_params = [] yield missing_params if missing_params.size > 1 raise ParamMultipleMissing.new(missing_params) elsif missing_params.size == 1 raise ParamMissing.new(missing_params.first) end end
Public Instance Methods
Source
# File lib/apipie/validator.rb, line 106 def ==(other) return false unless self.class == other.class if param_description == other.param_description true else false end end
Source
# File lib/apipie/validator.rb, line 66 def description "TODO: validator description" end
validator description
Source
# File lib/apipie/validator.rb, line 74 def error ParamInvalid.new(param_name, @error_value, description) end
Source
# File lib/apipie/validator.rb, line 89 def expected_type 'string' end
what type is expected, mostly string this information is used in cli client thor supported types :string, :hash, :array, :numeric, or :boolean
Source
# File lib/apipie/validator.rb, line 70 def format_description_value(value) "<code>#{CGI::escapeHTML(value.to_s)}</code>" end
Source
# File lib/apipie/validator.rb, line 93 def ignore_allow_blank? false end
Source
# File lib/apipie/validator.rb, line 20 def inspect string = "#<#{self.class.name}:#{self.object_id} " fields = inspected_fields.map {|field| "#{field}: #{self.send(field)}"} string << fields.join(", ") << ">" end
Source
# File lib/apipie/validator.rb, line 16 def inspected_fields [:param_description] end
Source
# File lib/apipie/validator.rb, line 97 def merge_with(other_validator) return self if self == other_validator raise NotImplementedError, "Don't know how to merge #{self.inspect} with #{other_validator.inspect}" end
Source
# File lib/apipie/validator.rb, line 61 def param_name @param_description.name end
Source
# File lib/apipie/validator.rb, line 51 def valid?(value) if self.validate(value) @error_value = nil true else @error_value = value false end end
check if value is valid