Method: MemoryModel::Collection::Finders#where

Defined in:
lib/memory_model/collection/finders.rb

#where(hash) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/memory_model/collection/finders.rb', line 43

def where(hash)
  matched_ids = hash.symbolize_keys.reduce(_uuids_) do |array, (attr, value)|
    records = if indexes.has_key?(attr)
                where_in_index(attr, value).compact.map(&:uuid)
              else
                where_in_all(attr, value).map(&:_uuid_)
              end
    array & records
  end
  load_all(*matched_ids)
end