Sha256: 42bbdb29b739d9702bc8d1d28c74181a4468045aa667bf9c88ee141899ee7792
Contents?: true
Size: 926 Bytes
Versions: 9
Compression:
Stored size: 926 Bytes
Contents
module CassandraObject class Scope module FinderMethods def find(ids) if ids.is_a?(Array) find_some(ids) else find_one(ids) end end def find_by_id(ids) find(ids) rescue CassandraObject::RecordNotFound nil end def all to_a end def first limit(1).to_a.first end private def find_one(id) if id.blank? raise CassandraObject::RecordNotFound, "Couldn't find #{self.name} with key #{id.inspect}" elsif record = where('KEY' => id).first record else raise CassandraObject::RecordNotFound end end def find_some(ids) ids = ids.flatten return [] if ids.empty? ids = ids.compact.map(&:to_s).uniq where("KEY" => ids).to_a end end end end
Version data entries
9 entries across 9 versions & 1 rubygems