Class: Purpose Abstract
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Purpose
- Includes:
- Relationship::Associations, Uuid::Uuidable
- 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 Relationship::Associations
Methods inherited from ApplicationRecord
convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
Methods included from Warren::BroadcastMessages
#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren
Instance Method Details
#barcode_type ⇒ Object
78 79 80 |
# File 'app/models/purpose.rb', line 78 def &.printer_type_id end |
#prefix=(prefix) ⇒ Object
86 87 88 |
# File 'app/models/purpose.rb', line 86 def prefix=(prefix) self. = BarcodePrefix.find_or_create_by(prefix: prefix) end |
#set_default_barcode_prefix ⇒ Object
90 91 92 |
# File 'app/models/purpose.rb', line 90 def self.prefix ||= default_prefix end |
#source_plate(labware) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/models/purpose.rb', line 54 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.stock_plate end end |
#source_plates(labware) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'app/models/purpose.rb', line 64 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.stock_plate].compact end end |
#source_purpose_name=(source_purpose_name) ⇒ Object
74 75 76 |
# File 'app/models/purpose.rb', line 74 def source_purpose_name=(source_purpose_name) self.source_purpose = Purpose.find_by!(name: source_purpose_name) end |
#target_class ⇒ Object
82 83 84 |
# File 'app/models/purpose.rb', line 82 def target_class target_type.constantize end |