Class: AssetGroup

Inherits:
ApplicationRecord show all
Includes:
ModelExtensions::AssetGroup, SharedBehaviour::Named, Uuid::Uuidable
Defined in:
app/models/asset_group.rb

Overview

Groups a set of receptacles together Primarily used to group together receptacles as part of an order.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedBehaviour::Named

included

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

extended

Class Method Details

.find_or_create_asset_group(new_assets_name, study) ⇒ Object



40
41
42
43
44
45
# File 'app/models/asset_group.rb', line 40

def self.find_or_create_asset_group(new_assets_name, study)
  # Is new name set or create group
  asset_group = nil
  asset_group = AssetGroup.create_with(study:).find_or_create_by(name: new_assets_name) if new_assets_name.present?
  asset_group
end

Instance Method Details

#all_samples_have_accession_numbers?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/asset_group.rb', line 24

def all_samples_have_accession_numbers?
  unaccessioned_samples.empty?
end

#asset_typesObject



51
52
53
# File 'app/models/asset_group.rb', line 51

def asset_types
  assets.map(&:sti_type).uniq
end

#automatic_move?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/asset_group.rb', line 47

def automatic_move?
  asset_types.one? && assets.first.automatic_move?
end

#unaccessioned_samplesObject

The has many through only works if the asset_group_assets are stored in the database, which won’t be the case for new records. We depend on checking this on unsaved asset groups during the submission process. Here we switch between to scopes.



31
32
33
34
35
36
37
38
# File 'app/models/asset_group.rb', line 31

def unaccessioned_samples
  if new_record?
    # We map id here to stop rails being too clever and passib in the unsaved scope
    Sample.contained_in(assets.map(&:id)).without_accession
  else
    samples.without_accession
  end
end