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

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


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

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)

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

def all_samples_have_accession_numbers?
  unaccessioned_samples.empty?
end

#asset_typesObject


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

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

#automatic_move?Boolean

Returns:

  • (Boolean)

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

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.


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

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