Class: PickList

Inherits:
ApplicationRecord show all
Defined in:
app/models/pick_list.rb

Overview

A pick list is a lightweight wrapper to provide a simplified interface for automatically generating batches for the CherrypickPipeline. It is intended to isolate external applications from the implementation and to provide an interface for eventually building a simplified means for generating cherrypicks

Defined Under Namespace

Classes: Pick, RecordCache

Constant Summary collapse

REQUEST_TYPE_KEY =
'cherrypick'

Instance Method Summary collapse

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Instance Method Details


62
63
64
65
66
67
# File 'app/models/pick_list.rb', line 62

def links
  [{ name: "Pick-list #{id}", url: url_helpers.pick_list_url(self, host: configatron.site_url) }] +
    batches.map do |batch|
      { name: "Batch #{batch.id}", url: url_helpers.batch_url(batch, host: configatron.site_url) }
    end
end

#pick_attributesObject


45
46
47
48
49
50
51
# File 'app/models/pick_list.rb', line 45

def pick_attributes
  orders.flat_map do |order|
    order.assets.map do |source_receptacle|
      { source_receptacle: source_receptacle, study: order.study, project: order.project }
    end
  end
end

#pick_attributes=(picks) ⇒ Array<PickList::Pick>

Build a list of picks based on the supplied array of pick-attributes

Parameters:

  • picks (Hash)

    Array of hashes with the following parameters source_receptacle: The source Receptacle study: The Study associated with the pick project: The Project to charge for the pick

    study and project are not required is already set on the aliquots in the source_receptacle

Returns:


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

def pick_attributes=(picks)
  picks
    .map { |pick| Pick.new(pick) }
    .group_by(&:order_options)
    .each { |order_options, pick_group| orders << build_order(pick_group, order_options) }
end

#process_immediatelyObject


69
70
71
72
73
# File 'app/models/pick_list.rb', line 69

def process_immediately
  submission.process_synchronously!
  create_batch!
  update!(state: :built)
end

#receptaclesObject

We can't use a has-many through, as we end up modifying the association and the setter above won't automatically update the getter that has_many would define. TODO: Some performance improvements here, but will revisit once the API stabilizes

as I'm tempted to use 'picks' instead.

58
59
60
# File 'app/models/pick_list.rb', line 58

def receptacles
  orders.flat_map(&:assets)
end