Class: ProgramsValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ProgramsValidator
- Defined in:
- app/models/concerns/programs_validator.rb
Overview
Validates the program attribute for PrimerPanel A program identifies the PCR program that should be operated at different stages of the pipeline (Stages listed in PROGRAMS_LABELS) and the expected duration of that step.
Constant Summary collapse
- PROGRAMS_LABELS =
attribute should be of the form: {‘pcr 1’ => { ‘name’ => “pcr1 program”, ‘duration’ => 45 }, ‘pcr 2’ => { ‘name’ => “pcr2 program” , ‘duration’ => 20 }}
['pcr 1', 'pcr 2'].freeze
- PROGRAMS_PARAMS =
%w[name duration].freeze
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/concerns/programs_validator.rb', line 15 def validate_each(record, attribute, value) return unless check_hash(record, attribute, value) value.each do |program, params| record.errors.add attribute, "invalid label #{program}" unless program.in?(PROGRAMS_LABELS) params.each do |key, val| record.errors.add attribute, "invalid attribute #{key}" unless key.in?(PROGRAMS_PARAMS) validate_duration(record, attribute, val) if key == 'duration' end end end |