Class: PlatePurpose

Inherits:
Purpose show all
Includes:
Api::PlatePurposeIO::Extensions, Overrideable, Purpose::Relationship::Associations, SharedBehaviour::Named
Defined in:
app/models/plate_purpose.rb

Defined Under Namespace

Modules: BroadcastLibraryComplete, Initial, Library, Overrideable, RequestAttachment, Stock, WorksOnLibraryRequests Classes: InitialPurpose, Input

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Api::PlatePurposeIO::Extensions

included, #json_root

Methods included from Purpose::Relationship::Associations

included

Methods included from SharedBehaviour::Named

included

Methods inherited from Purpose

#barcode_type, #prefix=, #set_default_barcode_prefix, #target_class

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

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

Class Method Details

.stock_plate_purposeObject


125
126
127
# File 'app/models/plate_purpose.rb', line 125

def self.stock_plate_purpose
  PlatePurpose.create_with(stock_plate: true, cherrypickable_target: true).find_or_create_by!(name: 'Stock Plate')
end

Instance Method Details

#asset_shapeObject


30
31
32
# File 'app/models/plate_purpose.rb', line 30

def asset_shape
  super || AssetShape.default
end

#attatched?(_plate) ⇒ Boolean


150
151
152
# File 'app/models/plate_purpose.rb', line 150

def attatched?(_plate)
  true
end

#cherrypick_completed(plate) ⇒ Object


44
45
46
# File 'app/models/plate_purpose.rb', line 44

def cherrypick_completed(plate)
  messenger_creators.each { |creator| creator.create!(plate) }
end

#cherrypick_in_rows?Boolean


146
147
148
# File 'app/models/plate_purpose.rb', line 146

def cherrypick_in_rows?
  cherrypick_direction == 'row'
end

#child_plate_purposesObject


154
155
156
# File 'app/models/plate_purpose.rb', line 154

def child_plate_purposes
  child_purposes.where_is_a(PlatePurpose)
end

#create!(*args, &block) ⇒ Object


133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/models/plate_purpose.rb', line 133

def create!(*args, &block)
  attributes          = args.extract_options!
  do_not_create_wells = args.first.present?
  attributes[:size] ||= size
  attributes[:purpose] = self
  number = attributes.delete(:barcode)
  prefix = (attributes.delete(:barcode_prefix) || barcode_prefix).prefix
  attributes[:sanger_barcode] ||= { prefix: prefix, number: number }
  target_class.create_with_barcode!(attributes, &block).tap do |plate|
    plate.wells.construct! unless do_not_create_wells
  end
end

#input_plate=(is_input) ⇒ Object

Set the class to PlatePurpose::Input is set to true. Allows creation of the input plate purposes through the API without directly exposing our class names.


77
78
79
# File 'app/models/plate_purpose.rb', line 77

def input_plate=(is_input)
  self.type = 'PlatePurpose::Input' if is_input
end

#plate_heightObject


48
49
50
# File 'app/models/plate_purpose.rb', line 48

def plate_height
  asset_shape.plate_height(size)
end

#plate_widthObject


52
53
54
# File 'app/models/plate_purpose.rb', line 52

def plate_width
  asset_shape.plate_width(size)
end

#pool_wells(wells) ⇒ Object


108
109
110
111
112
113
114
115
116
# File 'app/models/plate_purpose.rb', line 108

def pool_wells(wells)
  _pool_wells(wells)
    .joins('LEFT OUTER JOIN uuids AS pool_uuids ON pool_uuids.resource_type="Submission" AND pool_uuids.resource_id=submission_id')
    .select('pool_uuids.external_id AS pool_uuid')
    .readonly(false)
    .tap do |wells_with_pool|
      raise StandardError, 'Cannot deal with a well in multiple pools' if wells_with_pool.group_by(&:id).any? { |_, multiple_pools| multiple_pools.uniq.size > 1 }
    end
end

#sizeObject


129
130
131
# File 'app/models/plate_purpose.rb', line 129

def size
  super || 96
end

#source_plate(plate) ⇒ Object Also known as: library_source_plate


34
35
36
# File 'app/models/plate_purpose.rb', line 34

def source_plate(plate)
  source_purpose_id.present? ? plate.ancestor_of_purpose(source_purpose_id) : plate.stock_plate
end

#source_plates(plate) ⇒ Object Also known as: library_source_plates


39
40
41
# File 'app/models/plate_purpose.rb', line 39

def source_plates(plate)
  source_purpose_id.present? ? plate.ancestors_of_purpose(source_purpose_id) : [plate.stock_plate]
end

#source_wells_for(stock_wells) ⇒ Object


158
159
160
# File 'app/models/plate_purpose.rb', line 158

def source_wells_for(stock_wells)
  stock_wells
end

#state_of(plate) ⇒ Object

The state of a plate is based on the transfer requests.


57
58
59
# File 'app/models/plate_purpose.rb', line 57

def state_of(plate)
  plate.state_from(plate.transfer_requests)
end

#supports_multiple_submissions?Boolean


162
163
164
# File 'app/models/plate_purpose.rb', line 162

def supports_multiple_submissions?
  false
end

#transition_to(plate, state, _user, contents = nil, customer_accepts_responsibility = false) ⇒ Object

Updates the state of the specified plate to the specified state. The basic implementation does this by updating all of the TransferRequest instances to the state specified. If contents is blank then the change is assumed to relate to all wells of the plate, otherwise only the selected ones are updated.


64
65
66
67
68
69
70
# File 'app/models/plate_purpose.rb', line 64

def transition_to(plate, state, _user, contents = nil, customer_accepts_responsibility = false)
  wells = plate.wells
  wells = wells.located_at(contents) unless contents.blank?

  transition_state_requests(wells, state)
  fail_stock_well_requests(wells, customer_accepts_responsibility) if state == 'failed'
end