Class: PickList::RecordCache

Inherits:
Object
  • Object
show all
Defined in:
app/models/pick_list/record_cache.rb

Overview

The record cache collects all ids used in the request and optimizes the lookup into a single query, with appropriate eager loading. Built for use with Api::V2::PickListResource

Direct Known Subclasses

ByLabware, ByReceptacle

Defined Under Namespace

Classes: ByLabware, ByReceptacle

Constant Summary collapse

RECEPTACLE_KEYS =
%i[source_receptacle_id study_id project_id].freeze
LABWARE_KEYS =
%i[source_labware_id source_labware_barcode study_id project_id].freeze

Instance Method Summary collapse

Constructor Details

#initialize(picks) ⇒ RecordCache

Create a new cache

Parameters:

  • picks (Array<Hash>)

    An array of hashes describing picks.



91
92
93
94
# File 'app/models/pick_list/record_cache.rb', line 91

def initialize(picks)
  @store = Hash.new { |hash, key| hash[key] = Set.new }
  picks.each { |pick| add(pick) }
end

Instance Method Details

#add(entry) ⇒ Object



96
97
98
# File 'app/models/pick_list/record_cache.rb', line 96

def add(entry)
  self.class::KEYS.each { |key| @store[key] << entry[key] }
end