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 assets together Primarily used to group together assets 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

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

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

Class Method Details

.find_or_create_asset_group(new_assets_name, study) ⇒ Object


36
37
38
39
40
41
42
43
# File 'app/models/asset_group.rb', line 36

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

Instance Method Details

#all_samples_have_accession_numbers?Boolean

Returns:

  • (Boolean)

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

def all_samples_have_accession_numbers?
  unaccessioned_samples.empty?
end

#asset_typesObject


49
50
51
# File 'app/models/asset_group.rb', line 49

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

#automatic_move?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'app/models/asset_group.rb', line 45

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.


28
29
30
31
32
33
34
# File 'app/models/asset_group.rb', line 28

def unaccessioned_samples
  if new_record?
    Sample.contained_in(assets).without_accession
  else
    samples.without_accession
  end
end