Class: TagLayoutTemplate
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- TagLayoutTemplate
- Includes:
- Lot::Template, Uuid::Uuidable
- Defined in:
- app/models/tag_layout_template.rb
Overview
This is a layout template for tags. Think of it as a partially created TagLayout, defining only the tag group that will be used and the actual TagLayout implementation that will do the work.
Instance Method Summary collapse
-
#create!(attributes = {}, &block) ⇒ Object
Create a TagLayout instance that does the actual work of laying out the tags.
- #record_template_use(plate, enforce_uniqueness) ⇒ Object
- #stamp_to(_) ⇒ Object
- #tag2_group_name=(name) ⇒ Object
- #tag_group_name=(name) ⇒ Object
Methods included from Lot::Template
Methods included from Uuid::Uuidable
included, #unsaved_uuid!, #uuid
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
#create!(attributes = {}, &block) ⇒ Object
Create a TagLayout instance that does the actual work of laying out the tags.
27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/tag_layout_template.rb', line 27 def create!(attributes = {}, &block) new_tag_layout_attributes = attributes.except(:enforce_uniqueness).merge(tag_layout_attributes) # By default if not overridden, dual indexed tag template enforce their uniqueness # We use fetch here, as both nil and false are expected values enforce_uniqueness = attributes.fetch(:enforce_uniqueness, tag2_group.present?) TagLayout .create!(new_tag_layout_attributes, &block) .tap { |tag_layout| record_template_use(tag_layout.plate, enforce_uniqueness) } end |
#record_template_use(plate, enforce_uniqueness) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'app/models/tag_layout_template.rb', line 46 def record_template_use(plate, enforce_uniqueness) plate.submissions.each do |submission| TagLayout::TemplateSubmission.create!( submission: submission, tag_layout_template: self, enforce_uniqueness: enforce_uniqueness ) end end |
#stamp_to(_) ⇒ Object
22 23 24 |
# File 'app/models/tag_layout_template.rb', line 22 def stamp_to(_) # Do Nothing end |
#tag2_group_name=(name) ⇒ Object
42 43 44 |
# File 'app/models/tag_layout_template.rb', line 42 def tag2_group_name=(name) self.tag2_group = TagGroup.find_by!(name:) end |
#tag_group_name=(name) ⇒ Object
38 39 40 |
# File 'app/models/tag_layout_template.rb', line 38 def tag_group_name=(name) self.tag_group = TagGroup.find_by!(name:) end |