Class: Restapi::Validator::BaseValidator
- Inherits:
-
Object
- Object
- Restapi::Validator::BaseValidator
- Defined in:
- lib/restapi/validator.rb
Overview
to create new validator, inherit from Restapi::Validator::Base and implement class method build and instance method validate
Direct Known Subclasses
ArrayValidator, HashValidator, ProcValidator, RegexpValidator, TypeValidator
Instance Attribute Summary collapse
-
#param_name ⇒ Object
Returns the value of attribute param_name.
Class Method Summary collapse
-
.find(argument, options, block) ⇒ Object
find the right validator for given options.
Instance Method Summary collapse
-
#description ⇒ Object
validator description.
- #to_json ⇒ Object
- #to_s ⇒ Object
-
#valid?(value) ⇒ Boolean
check if value is valid.
Instance Attribute Details
#param_name ⇒ Object
Returns the value of attribute param_name.
9 10 11 |
# File 'lib/restapi/validator.rb', line 9 def param_name @param_name end |
Class Method Details
.find(argument, options, block) ⇒ Object
find the right validator for given options
12 13 14 15 16 17 18 |
# File 'lib/restapi/validator.rb', line 12 def self.find(argument, , block) self.subclasses.each do |validator_type| validator = validator_type.build(argument, , block) return validator if validator end return nil end |
Instance Method Details
#description ⇒ Object
validator description
32 33 34 |
# File 'lib/restapi/validator.rb', line 32 def description "TODO: validator description" end |
#to_json ⇒ Object
40 41 42 |
# File 'lib/restapi/validator.rb', line 40 def to_json self.description end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/restapi/validator.rb', line 36 def to_s self.description end |
#valid?(value) ⇒ Boolean
check if value is valid
21 22 23 24 25 26 27 28 29 |
# File 'lib/restapi/validator.rb', line 21 def valid?(value) if self.validate(value) @error_value = nil true else @error_value = value false end end |