Class: BetterValidations::NestedValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- BetterValidations::NestedValidator
- Defined in:
- lib/better_validations/nested_validator.rb
Instance Attribute Summary collapse
-
#validator_class ⇒ Object
readonly
Returns the value of attribute validator_class.
Instance Method Summary collapse
-
#initialize(options) ⇒ NestedValidator
constructor
A new instance of NestedValidator.
- #validate_each(record, attr_name, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ NestedValidator
4 5 6 7 |
# File 'lib/better_validations/nested_validator.rb', line 4 def initialize() @validator_class = .delete(:validator_class) super end |
Instance Attribute Details
#validator_class ⇒ Object (readonly)
Returns the value of attribute validator_class.
2 3 4 |
# File 'lib/better_validations/nested_validator.rb', line 2 def validator_class @validator_class end |
Instance Method Details
#validate_each(record, attr_name, value) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/better_validations/nested_validator.rb', line 9 def validate_each(record, attr_name, value) return if value.nil? validator = init_validator(value) cache_validator(record, attr_name, validator) return if validator_valid?(validator) record.errors.add(error_key(attr_name), error_text) end |