Class: OutcomeValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- OutcomeValidator
- Defined in:
- lib/tram/validators/outcome_validator.rb
Overview
Validates attribute by applying validation rule not to the attribute itself, but to another parameter, whose value depends on the attribute.
The resulting error is collected under the attribute’s key, which is necessary to correctly bind the error to the field, that causes the problem.
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tram/validators/outcome_validator.rb', line 14 def validate_each(record, attribute, value) dependency = [:value].to_s.gsub(".", "_") dependent = Tram::Validators.chained_value(record, [:value]) validators = Tram::Validators.validators(@attributes, , :value) sandbox = record.dup validators.each do |condition, validator| next if valid_in_sandbox(sandbox, attribute, dependent, validator) key = (dependency, condition) text = (record, attribute, value, dependent, key) record.errors.add attribute, text end end |