Class: Plate::Creator

Inherits:
ApplicationRecord show all
Defined in:
app/models/plate/creator.rb

Defined Under Namespace

Classes: ParentPurposeRelationship, PurposeRelationship

Constant Summary collapse

PlateCreationError =
Class.new(StandardError)

Instance Method Summary collapse

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Instance Method Details

#execute(source_plate_barcodes, barcode_printer, scanned_user, creator_parameters = nil) ⇒ Object

Executes the plate creation so that the appropriate child plates are built.


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/plate/creator.rb', line 29

def execute(source_plate_barcodes, barcode_printer, scanned_user, creator_parameters = nil)
  ActiveRecord::Base.transaction do
    new_plates = create_plates(source_plate_barcodes, scanned_user, creator_parameters)
    return false if new_plates.empty?

    new_plates.group_by(&:plate_purpose).each do |plate_purpose, plates|
      print_job = LabelPrinter::PrintJob.new(barcode_printer.name,
                                             LabelPrinter::Label::PlateCreator,
                                             plates: plates, plate_purpose: plate_purpose, user_login: scanned_user.)
      return false unless print_job.execute
    end
    true
  end
end