Class: HashValidator::Validator::JsonValidator
- Defined in:
- lib/hash_validator/validators/json_validator.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize ⇒ JsonValidator
constructor
A new instance of JsonValidator.
- #presence_error_message ⇒ Object
- #validate(key, value, _validations, errors) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize ⇒ JsonValidator
Returns a new instance of JsonValidator.
4 5 6 |
# File 'lib/hash_validator/validators/json_validator.rb', line 4 def initialize super('json') # The name of the validator end |
Instance Method Details
#presence_error_message ⇒ Object
8 9 10 |
# File 'lib/hash_validator/validators/json_validator.rb', line 8 def 'is not valid JSON' end |
#validate(key, value, _validations, errors) ⇒ Object
12 13 14 15 16 |
# File 'lib/hash_validator/validators/json_validator.rb', line 12 def validate(key, value, _validations, errors) unless value.is_a?(String) && valid_json?(value) errors[key] = end end |