Class: Validators::FailedValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/validators/failed_validator.rb

Overview

Displays a warning if libraries on the plate have been cancelled or failed but the well itself still appears active.

Instance Method Summary collapse

Instance Method Details

#active_wells_with_terminated_requests(labware) ⇒ Object



20
21
22
23
24
25
26
# File 'app/models/validators/failed_validator.rb', line 20

def active_wells_with_terminated_requests(labware)
  labware.wells.filter_map do |well|
    next if well.inactive? || well.active_requests.empty?

    well.location if well.active_requests.all?(&:failed?)
  end
end

#validate(presenter) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/validators/failed_validator.rb', line 7

def validate(presenter)
  problem_wells = active_wells_with_terminated_requests(presenter.labware)
  return true if problem_wells.empty?

  affected_range = WellHelpers.formatted_range(problem_wells, presenter.size)

  presenter.errors.add(
    :libraries,
    "on this plate have already been failed (#{affected_range}). You should not carry out further work. " \
      'Any further work conducted from this plate will run into issues at the end of the pipeline.'
  )
end