Class: ActiveModel::Validations::HashValuesValidator
- Inherits:
-
ArrayValidator
- Object
- EachValidator
- ArrayValidator
- ActiveModel::Validations::HashValuesValidator
- Defined in:
- lib/can_has_validations/validators/hash_values_validator.rb
Defined Under Namespace
Modules: HashValidatorKey
Instance Attribute Summary
Attributes inherited from ArrayValidator
Instance Method Summary collapse
-
#initialize(options) ⇒ HashValuesValidator
constructor
A new instance of HashValuesValidator.
- #validate_each(record, attribute, hash) ⇒ Object
- #validate_one(validator, record, attribute, key_and_value) ⇒ Object
Constructor Details
#initialize(options) ⇒ HashValuesValidator
Returns a new instance of HashValuesValidator.
24 25 26 27 28 |
# File 'lib/can_has_validations/validators/hash_values_validator.rb', line 24 def initialize() record_class = [:class] super record_class.include HashValidatorKey end |
Instance Method Details
#validate_each(record, attribute, hash) ⇒ Object
30 31 32 |
# File 'lib/can_has_validations/validators/hash_values_validator.rb', line 30 def validate_each(record, attribute, hash) super(record, attribute, Array(Hash(hash))) end |
#validate_one(validator, record, attribute, key_and_value) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/can_has_validations/validators/hash_values_validator.rb', line 34 def validate_one(validator, record, attribute, key_and_value) key, value = key_and_value record.hash_validator_key = key super(validator, record, attribute, value) ensure record.hash_validator_key = nil end |