Class: Sequencescape::Api::V2::Labware

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

Overview

A labware from sequencescape via the V2 API

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_all(options, includes: DEFAULT_INCLUDES) ⇒ Object

Other relationships has_one :purpose via Sequencescape::Api::V2::Shared::HasPurpose



23
24
25
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 23

def self.find_all(options, includes: DEFAULT_INCLUDES)
  Sequencescape::Api::V2::Labware.includes(*includes).where(options).all
end

.table_nameObject



8
9
10
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 8

def self.table_name
  'labware'
end

Instance Method Details

#find_stock_plateObject

‘ancestors’ returns different types based on the query used to retrieve ‘self’ if ancestors was ‘included’ in the query, you get an Array if not, you get a JsonApiClient::Query::Builder sometimes you can also get nil this method has no test - mocking was a nightmare and didn’t represent real API responses



73
74
75
76
77
78
79
80
81
82
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 73

def find_stock_plate
  stocks = SearchHelper.stock_plate_names
  return self if stock_plate?(purpose_names: stocks)

  if ancestors.instance_of?(Array)
    ancestors.select { |a| stocks.include? a.purpose.name }.max_by(&:id)
  elsif ancestors.instance_of?(JsonApiClient::Query::Builder)
    ancestors.where(purpose_name: stocks).order(id: :asc).last
  end
end

#input_barcodeObject

stock plate / input plate barcode ======


60
61
62
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 60

def input_barcode
  stock_plate.try(:barcode).try(:human)
end

#model_nameActiveModel::Name

Plates and tubes are handled by different URLs. This allows us to redirect to the expected endpoint.

Returns:

  • (ActiveModel::Name)

    The resource behaves like a Limber::Tube/Limber::Plate



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 32

def model_name
  case type
  when 'tubes'
    ::ActiveModel::Name.new(Limber::Tube, false)
  when 'plates'
    ::ActiveModel::Name.new(Limber::Plate, false)
  when 'tube_racks'
    ::ActiveModel::Name.new(Sequencescape::Api::V2::TubeRack, false, 'Limber::TubeRack')
  else
    raise "Can't view #{type} in limber"
  end
end

#plate?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 50

def plate?
  type == 'plates'
end

#stock_plateObject



64
65
66
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 64

def stock_plate
  @stock_plate ||= find_stock_plate
end

#stock_plate?(purpose_names: SearchHelper.stock_plate_names) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 84

def stock_plate?(purpose_names: SearchHelper.stock_plate_names)
  purpose_names.include?(purpose.name)
end

#to_paramObject

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



46
47
48
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 46

def to_param
  uuid
end

#tube?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 54

def tube?
  type == 'tubes'
end