Class: Purpose Abstract
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Purpose
- Defined in:
- app/models/purpose.rb
Overview
Probably best to avoid using directly.
Purpose was originally just a property of plates and so was originally just PlatePurpose. As a result its table, and the foreign key on labware are plate_purposes and plate_purpose_id despite the fact they can now be applied to tubes as well.
The Purpose of a piece of Labware describes its role in the lab. While most labware will retain a single purpose through their life cycle, it is possible for purpose to be changed. Ideally this should be performed with a PlateConversion to ensure proper tracking.
Historically Purpose has modified the behaviour of its corresponding Labware, with a number of methods, such as Plate#state delegating to Plate#plate_purpose. While this is still occasionally required, it tends to result in quite brittle, unflexible behaviour. More recently we have been trying to push these differences in business logic outwards. In this new approach the Pipeline handles differences in behaviour, and the purpose acts merely as a tag, which can be used to inform the pipeline how it may wish to proceed. This approach makes Labware far more interchangeable.
Information about which purpose classes are used, and their last activity can be generated by running: bundle exec rake report:purposes
in the appropriate environment. (Probably production)
Direct Known Subclasses
Defined Under Namespace
Classes: Relationship
Instance Method Summary collapse
- #barcode_type ⇒ Object
- #prefix=(prefix) ⇒ Object
- #set_default_barcode_prefix ⇒ Object
- #source_plate(labware) ⇒ Object
- #source_plates(labware) ⇒ Object
- #source_purpose_name=(source_purpose_name) ⇒ Object
- #target_class ⇒ Object
Methods included from Uuid::Uuidable
included, #unsaved_uuid!, #uuid
Methods included from SharedBehaviour::Named
Methods included from Relationship::Associations
Methods inherited from ApplicationRecord
alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
Instance Method Details
#barcode_type ⇒ Object
79 80 81 |
# File 'app/models/purpose.rb', line 79 def &.printer_type_id end |
#prefix=(prefix) ⇒ Object
87 88 89 |
# File 'app/models/purpose.rb', line 87 def prefix=(prefix) self. = BarcodePrefix.find_or_create_by(prefix:) end |
#set_default_barcode_prefix ⇒ Object
91 92 93 |
# File 'app/models/purpose.rb', line 91 def self.prefix ||= default_prefix end |
#source_plate(labware) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'app/models/purpose.rb', line 55 def source_plate(labware) # Stock_plate is deprecated, but we still have some tubes with special behaviour # We'll allow its usage here to support existing code. ActiveSupport::Deprecation.silence do # Rails 6 lets us do this: # ActiveSupport::Deprecation.allow(:stock_plate) do source_purpose_id.present? ? labware.ancestor_of_purpose(source_purpose_id) : labware.try(:stock_plate) end end |
#source_plates(labware) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'app/models/purpose.rb', line 65 def source_plates(labware) # Stock_plate is deprecated, but we still have some tubes with special behaviour # We'll allow its usage here ActiveSupport::Deprecation.silence do # Rails 6 lets us do this: # ActiveSupport::Deprecation.allow(:stock_plate) do source_purpose_id.present? ? labware.ancestors_of_purpose(source_purpose_id) : [labware.try(:stock_plate)].compact end end |
#source_purpose_name=(source_purpose_name) ⇒ Object
75 76 77 |
# File 'app/models/purpose.rb', line 75 def source_purpose_name=(source_purpose_name) self.source_purpose = Purpose.find_by!(name: source_purpose_name) end |
#target_class ⇒ Object
83 84 85 |
# File 'app/models/purpose.rb', line 83 def target_class target_type.constantize end |