Module: Submission::AssetSubmissionFinder

Included in:
BulkSubmission
Defined in:
app/models/submission/asset_submission_finder.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Instance Method Details

#find_all_assets_by_name_including_samples!(names) ⇒ Object


11
12
13
14
15
16
17
18
19
# File 'app/models/submission/asset_submission_finder.rb', line 11

def find_all_assets_by_name_including_samples!(names)
  Receptacle
    .for_bulk_submission
    .named(names)
    .tap do |found|
      missing = names - found.map(&:name)
      raise ActiveRecord::RecordNotFound, "Could not find Labware with names #{missing.inspect}" if missing.present?
    end
end

#find_tubes_including_samples_for!(details) ⇒ Object

rubocop:enable Metrics/MethodLength


40
41
42
43
44
45
46
47
48
49
# File 'app/models/submission/asset_submission_finder.rb', line 40

def find_tubes_including_samples_for!(details)
  Receptacle
    .on_a(Tube)
    .for_bulk_submission
    .with_barcode(details['barcode'])
    .tap do |found|
      missing = details['barcode'].reject { |barcode| found.any? { |tube| tube.any_barcode_matching?(barcode) } }
      raise ActiveRecord::RecordNotFound, "Could not find Tubes with barcodes #{missing.inspect}" if missing.present?
    end
end

#find_wells_including_samples_for!(details) ⇒ Object

rubocop:todo Metrics/MethodLength

Raises:

  • (StandardError)

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/submission/asset_submission_finder.rb', line 22

def find_wells_including_samples_for!(details) # rubocop:todo Metrics/AbcSize
  barcodes, well_list = details['barcode'], details['plate well']
  errors.add(:spreadsheet, 'You can only specify one plate per asset group') unless barcodes.uniq.one?
  barcode = barcodes.first
  plate = Plate.find_from_barcode(barcode)
  raise StandardError, "Cannot find plate with barcode #{barcode} for #{details['rows']}" if plate.nil?

  well_locations = well_list.map(&:strip)
  wells = plate.wells.for_bulk_submission.located_at(well_locations)
  if wells.length != well_locations.size
    raise StandardError, "Too few wells found for #{details['rows']}: #{wells.map(&:map).map(&:description).inspect}"
  end

  wells
end

#is_plate?(details) ⇒ Boolean

Returns:

  • (Boolean)

3
4
5
# File 'app/models/submission/asset_submission_finder.rb', line 3

def is_plate?(details)
  details['barcode'].present? && details['plate well'].present?
end

#is_tube?(details) ⇒ Boolean

Returns:

  • (Boolean)

7
8
9
# File 'app/models/submission/asset_submission_finder.rb', line 7

def is_tube?(details)
  details['barcode'].present? && details['plate well'].blank?
end