Class: ApplicationRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Warren::BroadcastMessages
Defined in:
app/models/application_record.rb

Overview

Basic base class for all ActiveRecord::Base records in Sequencescape

Direct Known Subclasses

Aker::Container, Aker::Job, Aliquot, AliquotIndex, ApiApplication, Asset, AssetAudit, AssetBarcode, AssetCreation, AssetGroup, AssetGroupAsset, AssetLink, AssetShape, BaitLibrary, BaitLibrary::Supplier, BaitLibraryLayout, BaitLibraryType, Barcode, BarcodePrefix, BarcodePrinter, BarcodePrinterType, Batch, BatchRequest, Billing::AgressoProduct, Billing::Item, Billing::Product, Billing::ProductCatalogue, BroadcastEvent, BudgetDivision, BulkTransfer, Comment, Control, CustomMetadatum, CustomMetadatumCollection, CustomText, DataReleaseStudyType, DbFile, Descriptor, Document, Equipment, Event, ExtendedValidator, ExtendedValidator::RequestTypeExtendedValidator, ExternalProperty, ExtractionAttribute, FacultySponsor, Failure, Family, Identifier, Implement, Item, LabEvent, LibraryType, LibraryTypesRequestType, LocationReport, Lot, LotType, Map, Messenger, MessengerCreator, Metadata::Base, Order, OrderRole, Permission, Pipeline, PipelineRequestInformationType, PipelinesRequestType, Plate::Creator, Plate::Creator::ParentPurposeRelationship, Plate::Creator::PurposeRelationship, PlateConversion, PlateOwner, PlateType, PlateVolume, PooledPlateCreation::ParentAssociation, PreCapturePool, PreCapturePool::PooledRequest, PrimerPanel, Product, ProductCatalogue, ProductCriteria, ProductLine, ProductProductCatalogue, Program, Project, ProjectManager, Purpose, Purpose::Relationship, QcAssay, QcDecision, QcDecision::QcDecisionQcable, QcFile, QcMetric, QcMetricRequest, QcReport, QcResult, Qcable, QcableCreator, ReferenceGenome, Request, RequestClassDeprecator::Request, RequestEvent, RequestInformation, RequestInformationType, RequestType, RequestType::PoolingMethod, RequestType::RequestTypePlatePurpose, RequestType::Validator, Robot, RobotProperty, Role, Role::UserRole, Sample, SampleJob, SampleManifest, SampleManifestAsset, SampleRegistrar, SangerSampleId, Search, SpecificTubeCreation::ChildPurpose, Stamp, Stamp::StampQcable, StateChange, Study, StudyReport, StudySample, StudyType, SubclassAttribute, Submission, SubmissionPool, SubmissionTemplate, SubmissionTemplateRequestType, SubmittedAsset, Supplier, Tag, Tag2Layout, Tag2Layout::TemplateSubmission, Tag2LayoutTemplate, TagGroup, TagGroup::AdapterType, TagLayout, TagLayout::TemplateSubmission, TagLayoutTemplate, Task, Transfer, Transfer::BetweenPlateAndTubes::WellToTube, TransferRequest, TransferRequestCollection, TransferRequestCollectionTransferRequest, TransferTemplate, TubeCreation::ChildTube, User, Uuid, VolumeUpdate, Well::Link, WellAttribute, WorkCompletion, WorkCompletionsSubmission, WorkOrder, WorkOrderType, Workflow

Class Method Summary collapse

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Class Method Details

.convert_labware_to_receptacle_for(*associations) ⇒ Object

Temporary compatibility layer while AssetRefactor progresses will allow labware to get passed into associations expecting receptacles where there is no ambiguity. (e.g. tubes)

Examples:

convert_labware_to_receptacle_for :library
def library=(library)
  return super if library.is_a?(Receptacle)
  Rails.logger.warn("#{library.class.name} passed to library")
  super(library.receptacle)
end

42
43
44
45
46
47
48
49
50
51
# File 'app/models/application_record.rb', line 42

def convert_labware_to_receptacle_for(*associations)
  associations.each do |assn|
    define_method("#{assn}=") do |associated|
      return super(associated) if associated.is_a?(Receptacle)

      Rails.logger.warn("#{associated.class.name} passed to #{assn}")
      super(associated&.receptacle)
    end
  end
end

.find_by_id_or_name(id, name) ⇒ Object

Raises:

  • (StandardError)

25
26
27
28
29
30
# File 'app/models/application_record.rb', line 25

def find_by_id_or_name(id, name)
  return find(id) if id.present?
  raise StandardError, 'Must specify at least ID or name' if name.blank?

  find_by(name: name)
end

.find_by_id_or_name!(id, name) ⇒ Object


21
22
23
# File 'app/models/application_record.rb', line 21

def find_by_id_or_name!(id, name)
  find_by_id_or_name(id, name) || raise(ActiveRecord::RecordNotFound, "Could not find #{self.name}: #{id || name}")
end