Class: PickList
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PickList
- 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
- #links ⇒ Object
- #pick_attributes ⇒ Object
-
#pick_attributes=(picks) ⇒ Array<PickList::Pick>
Build a list of picks based on the supplied array of pick-attributes.
- #process_immediately ⇒ Object
-
#receptacles ⇒ Object
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.
Methods inherited from ApplicationRecord
alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
Instance Method Details
#links ⇒ Object
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_attributes ⇒ Object
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
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 { |, pick_group| orders << build_order(pick_group, ) } end |
#process_immediately ⇒ Object
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 |
#receptacles ⇒ Object
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 |