Class: JsonValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- JsonValidator
- Defined in:
- lib/json_validator.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ JsonValidator
constructor
A new instance of JsonValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ JsonValidator
Returns a new instance of JsonValidator.
6 7 8 9 |
# File 'lib/json_validator.rb', line 6 def initialize() .reverse_merge!(message: :invalid_json) super end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/json_validator.rb', line 11 def validate_each(record, attribute, value) return if json?(value) = .fetch(:message) record.errors.add(attribute, ) end |