Class: Fiona7::Prefetch::ObjPrefetch

Inherits:
Object
  • Object
show all
Defined in:
lib/fiona7/prefetch/obj_prefetch.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, prefetch_ids = []) ⇒ ObjPrefetch

Returns a new instance of ObjPrefetch.



6
7
8
9
10
11
12
# File 'lib/fiona7/prefetch/obj_prefetch.rb', line 6

def initialize(klass, prefetch_ids=[])
  self.klass          = klass
  self.prefetched_ids = Set.new
  self.object_id_map  = {}

  self.prefetch_objects(prefetch_ids)
end

Instance Method Details

#find_many(ids) ⇒ Object

Returns an array with objects for given IDs. The array is ordered according to the IDs given. For missing objects the array is filled with nil values



22
23
24
25
# File 'lib/fiona7/prefetch/obj_prefetch.rb', line 22

def find_many(ids)
  self.prefetch_objects(ids)
  ids.map { |id| self.object_id_map[id.to_i] }
end

#find_one(id) ⇒ Object

Returns an object with given ID or nil if no matching object found



15
16
17
# File 'lib/fiona7/prefetch/obj_prefetch.rb', line 15

def find_one(id)
  self.find_many([id]).first
end