Class: Validators::ActiveRequestValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- Validators::ActiveRequestValidator
- Defined in:
- app/models/validators/active_request_validator.rb
Overview
Displays a warning if wells are active (ie. not empty/failed/cancelled) and yet don’t have active requests associated with them.
Instance Method Summary collapse
- #active_wells_without_active_requests(labware) ⇒ Object
- #error_for(well) ⇒ Object
- #validate(presenter) ⇒ Object
Instance Method Details
#active_wells_without_active_requests(labware) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/validators/active_request_validator.rb', line 22 def active_wells_without_active_requests(labware) labware .wells .each_with_object(Hash.new { |h, i| h[i] = [] }) do |well, store| next if well.inactive? || well.active_requests.present? well_error = error_for(well) store[well_error] << well.location end end |
#error_for(well) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'app/models/validators/active_request_validator.rb', line 33 def error_for(well) if well.all_requests.empty? 'no associated requests' elsif well.all_requests.all?(&:cancelled?) 'cancelled requests' else 'requests not recognized by Limber' end end |
#validate(presenter) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/validators/active_request_validator.rb', line 7 def validate(presenter) problem_wells = active_wells_without_active_requests(presenter.labware) return true if problem_wells.empty? problem_wells.each do |error, wells| affected_range = WellHelpers.formatted_range(wells, presenter.size) presenter.errors.add( :wells, "on this plate (#{affected_range}) have #{error}. 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 end |