Class: Heron::Factories::Plate

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, Concerns::Contents, Concerns::CoordinatesSupport, Concerns::Eventful, Concerns::ForeignBarcodes, Concerns::RecipientsCoordinates
Defined in:
app/models/heron/factories/plate.rb

Overview

Factory class to create Heron tube racks

Constant Summary

Constants included from Concerns::CoordinatesSupport

Concerns::CoordinatesSupport::LOCATION_REGEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Eventful

#add_all_errors_from_event, #add_all_errors_from_events, #build_events, #params_for_event, #rollback_for_events

Methods included from Concerns::Contents

#_factories_for_location, #add_aliquots_into_location, #add_aliquots_into_locations, #contents, included, #label_for_error_message, #params_for_contents, #study_uuid

Methods included from Concerns::RecipientsCoordinates

#check_recipient_coordinates, included

Methods included from Concerns::CoordinatesSupport

#coordinate_valid?, #unpad_coordinate

Methods included from Concerns::ForeignBarcodes

#barcode_format, #check_barcode_format, #check_foreign_barcode_unique, included

Constructor Details

#initialize(params) ⇒ Plate

Returns a new instance of Plate.



18
19
20
# File 'app/models/heron/factories/plate.rb', line 18

def initialize(params)
  @params = params
end

Instance Attribute Details

#plateObject

Returns the value of attribute plate.



14
15
16
# File 'app/models/heron/factories/plate.rb', line 14

def plate
  @plate
end

#purposeObject

Returns the value of attribute purpose.



14
15
16
# File 'app/models/heron/factories/plate.rb', line 14

def purpose
  @purpose
end

Instance Method Details

#barcodeObject



30
31
32
# File 'app/models/heron/factories/plate.rb', line 30

def barcode
  @params[:barcode]
end

#content_factoryObject



26
27
28
# File 'app/models/heron/factories/plate.rb', line 26

def content_factory
  ::Heron::Factories::Sample
end

#recipients_keyObject



22
23
24
# File 'app/models/heron/factories/plate.rb', line 22

def recipients_key
  :wells
end

#sample_study_namesObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/heron/factories/plate.rb', line 56

def sample_study_names
  return unless @plate

  @plate
    .wells
    .each_with_object([]) do |well, study_names|
      next if well.aliquots.first.blank?

      study_names << well.aliquots.first.study.name if well.aliquots.first.study.present?
    end
    .uniq
end

#saveObject

rubocop:todo Metrics/MethodLength



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/heron/factories/plate.rb', line 34

def save # rubocop:todo Metrics/MethodLength
  return false unless valid?

  @output_result = true
  ActiveRecord::Base.transaction do
    @plate = purpose.create!

    Barcode.create!(labware: @plate, barcode: barcode, format: barcode_format)

    create_contents!

    if @params[:events]
      events = build_events(@plate)
      events.each do |event|
        rollback_for_events(events) unless event.valid?
        event.save
      end
    end
  end
  @output_result
end