Module: Pinky::ModelFetchMethods

Defined in:
lib/pinky/model_fetch_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



3
4
5
# File 'lib/pinky/model_fetch_methods.rb', line 3

def self.extended(base)
  base.extend HasCaches unless base.is_a? HasCaches
end

Instance Method Details

#find(query_hash = {}) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
# File 'lib/pinky/model_fetch_methods.rb', line 7

def find(query_hash = {})
  query_hash = { :id => query_hash } unless query_hash.is_a?(Hash)
  cache_name = Cache.name_for(*query_hash.keys)
  raise NotFoundException.new unless cache = pinky_caches_by_name[cache_name]
  found_object = cache.query(query_hash)
  return found_object unless found_object.nil?
  item_hash = lookup_item_hash query_hash
  update_caches_with item_hash
end