Class: Sequencescape::Api::V2::Labware
- Inherits:
-
Base
- Object
- Base
- Sequencescape::Api::V2::Labware
- 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
-
.find_all(options, includes: DEFAULT_INCLUDES) ⇒ Object
Other relationships has_one :purpose via Sequencescape::Api::V2::Shared::HasPurpose.
- .table_name ⇒ Object
Instance Method Summary collapse
-
#find_stock_plate ⇒ Object
‘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.
-
#input_barcode ⇒ Object
stock plate / input plate barcode ======.
-
#model_name ⇒ ActiveModel::Name
Plates and tubes are handled by different URLs.
- #plate? ⇒ Boolean
- #stock_plate ⇒ Object
- #stock_plate?(purpose_names: SearchHelper.stock_plate_names) ⇒ Boolean
-
#to_param ⇒ Object
Currently use the uuid as our main identifier, might switch to human barcode soon.
- #tube? ⇒ Boolean
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(, includes: DEFAULT_INCLUDES) Sequencescape::Api::V2::Labware.includes(*includes).where().all end |
.table_name ⇒ Object
8 9 10 |
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 8 def self.table_name 'labware' end |
Instance Method Details
#find_stock_plate ⇒ Object
‘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_barcode ⇒ Object
stock plate / input plate barcode ======
60 61 62 |
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 60 def stock_plate.try(:barcode).try(:human) end |
#model_name ⇒ ActiveModel::Name
Plates and tubes are handled by different URLs. This allows us to redirect to the expected endpoint.
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
50 51 52 |
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 50 def plate? type == 'plates' end |
#stock_plate ⇒ Object
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
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_param ⇒ Object
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
54 55 56 |
# File 'app/sequencescape/sequencescape/api/v2/labware.rb', line 54 def tube? type == 'tubes' end |