Class: HashValidator::Validator::ClassValidator
- Defined in:
- lib/hash_validator/validators/class_validator.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize ⇒ ClassValidator
constructor
A new instance of ClassValidator.
- #should_validate?(rhs) ⇒ Boolean
- #validate(key, value, klass, errors) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize ⇒ ClassValidator
Returns a new instance of ClassValidator.
2 3 4 |
# File 'lib/hash_validator/validators/class_validator.rb', line 2 def initialize super('_class') # The name of the validator, underscored as it won't usually be directly invoked (invoked through use of validator) end |
Instance Method Details
#should_validate?(rhs) ⇒ Boolean
6 7 8 |
# File 'lib/hash_validator/validators/class_validator.rb', line 6 def should_validate?(rhs) rhs.is_a?(Class) end |
#validate(key, value, klass, errors) ⇒ Object
10 11 12 13 14 |
# File 'lib/hash_validator/validators/class_validator.rb', line 10 def validate(key, value, klass, errors) unless value.is_a?(klass) errors[key] = "#{klass} required" end end |