Class: SequencingKitBoxBarcodeValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- SequencingKitBoxBarcodeValidator
- Includes:
- HasFilters
- Defined in:
- app/validators/sequencing_kit_box_barcode_validator.rb
Overview
Validator for sequencing kit box barcodes Validates the sequencing kit box barcodes for Revio runs
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options) ⇒ SequencingKitBoxBarcodeValidator
constructor
A new instance of SequencingKitBoxBarcodeValidator.
- #validate(record) ⇒ Object
-
#validate_sequencing_kit_box_barcode_count(record, existing_plates) ⇒ Object
For a given sequencing kit box barcode, check if the number of plates is less than the max number of plates allowed.
-
#validate_sequencing_kit_box_barcode_positions(record, existing_plates) ⇒ Object
For a given sequencing kit box barcode, check if the positions have already been used.
Methods included from HasFilters
#exclude_marked_for_destruction
Constructor Details
#initialize(options) ⇒ SequencingKitBoxBarcodeValidator
Returns a new instance of SequencingKitBoxBarcodeValidator.
12 13 14 15 |
# File 'app/validators/sequencing_kit_box_barcode_validator.rb', line 12 def initialize() super @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'app/validators/sequencing_kit_box_barcode_validator.rb', line 8 def @options end |
Instance Method Details
#validate(record) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/validators/sequencing_kit_box_barcode_validator.rb', line 17 def validate(record) existing_plates = Pacbio::Plate.where( sequencing_kit_box_barcode: record. ).where.not(id: record.id) # return unless there are existing sequencing kit barcodes return if existing_plates.blank? validations = %i[validate_sequencing_kit_box_barcode_count validate_sequencing_kit_box_barcode_positions] validations.each do |validation| next if record.errors.present? send(validation, record, existing_plates) end end |
#validate_sequencing_kit_box_barcode_count(record, existing_plates) ⇒ Object
For a given sequencing kit box barcode, check if the number of plates is less than the max number of plates allowed
38 39 40 41 42 43 44 45 |
# File 'app/validators/sequencing_kit_box_barcode_validator.rb', line 38 def (record, existing_plates) return unless existing_plates.count >= [:max_number_of_plates] record .errors.add(:plates, 'sequencing kit box barcode has already been used on ' \ "#{[:max_number_of_plates]} plates") end |
#validate_sequencing_kit_box_barcode_positions(record, existing_plates) ⇒ Object
For a given sequencing kit box barcode, check if the positions have already been used
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/validators/sequencing_kit_box_barcode_validator.rb', line 50 def (record, existing_plates) # filter wells based on exclusions record_wells = filtered(record.wells) # Get the common positions between the existing plates and the record wells common_positions = existing_plates.map(&:wells).flatten.map(&:position) & record_wells.map(&:position) return unless common_positions.any? positions = common_positions.join(',') record.errors .add(:plates, "#{positions} have already been used for plate #{record.}") end |