Class: Sequencescape::Api::V2::Tube

Inherits:
Base
  • Object
show all
Includes:
Shared::HasBarcode, Shared::HasPurpose, Shared::HasRequests, Shared::HasWorklineIdentifier
Defined in:
app/sequencescape/sequencescape/api/v2/tube.rb

Overview

Tubes can be barcoded, but only have one receptacle for samples.

Constant Summary collapse

DEFAULT_INCLUDES =
[
  :purpose,
  'receptacle.aliquots.request.request_type',
  'receptacle.requests_as_source.request_type'
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_all(params) ⇒ Object



43
44
45
46
47
48
# File 'app/sequencescape/sequencescape/api/v2/tube.rb', line 43

def self.find_all(params)
  options = params.dup
  includes = options.delete(:includes) || DEFAULT_INCLUDES
  paginate = options.delete(:paginate) || {}
  Sequencescape::Api::V2::Tube.includes(*includes).where(**options).paginate(paginate).all
end

.find_by(params) ⇒ Object



37
38
39
40
41
# File 'app/sequencescape/sequencescape/api/v2/tube.rb', line 37

def self.find_by(params)
  options = params.dup
  includes = options.delete(:includes) || DEFAULT_INCLUDES
  Sequencescape::Api::V2::Tube.includes(*includes).find(**options).first
end

Instance Method Details

#aliquotsObject



33
34
35
# File 'app/sequencescape/sequencescape/api/v2/tube.rb', line 33

def aliquots
  receptacle&.aliquots
end

#model_nameActiveModel::Name

Override the model used in form/URL helpers to allow us to treat old and new api the same

Returns:

  • (ActiveModel::Name)

    The resource behaves like a Limber::Tube



58
59
60
# File 'app/sequencescape/sequencescape/api/v2/tube.rb', line 58

def model_name
  ::ActiveModel::Name.new(Limber::Tube, false)
end

#stock_plate(purpose_names: SearchHelper.stock_plate_names) ⇒ Object



67
68
69
70
71
# File 'app/sequencescape/sequencescape/api/v2/tube.rb', line 67

def stock_plate(purpose_names: SearchHelper.stock_plate_names)
  # this is an array not a collection so cant use order_by
  # max_by naturally sorts in ascending order
  @stock_plate ||= ancestors.where(purpose_name: purpose_names).max_by(&:id)
end

#to_paramObject

Currently us the uuid as our main identifier, might switch to human barcode soon



63
64
65
# File 'app/sequencescape/sequencescape/api/v2/tube.rb', line 63

def to_param
  uuid
end