Class: WellValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- WellValidator
- Defined in:
- app/validators/well_validator.rb
Overview
Failed validations return unprocessable_entity
Instance Method Summary collapse
- #validate(record) ⇒ Object
- #validate_tag_presence(record) ⇒ Object
- #validate_tag_uniqueness(record) ⇒ Object
Instance Method Details
#validate(record) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/validators/well_validator.rb', line 5 def validate(record) return unless record.base_used_aliquots.many? validations = %i[validate_tag_presence validate_tag_uniqueness] validations.each do |validation| next if record.errors.present? send(validation, record) end end |
#validate_tag_presence(record) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/validators/well_validator.rb', line 17 def validate_tag_presence(record) = record.base_used_aliquots.collect(&:tag) return unless .empty? || .any?(nil) record.errors.add(:tags, 'are missing from the libraries') nil end |
#validate_tag_uniqueness(record) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/validators/well_validator.rb', line 26 def validate_tag_uniqueness(record) = record.base_used_aliquots.collect(&:tag) return if .length == .uniq.length record.errors.add(:tags, "are not unique within the libraries for well #{record.position}") nil end |