Sha256: f5062dfb2d3d1613c33e7f60a6513fe744baf183604a3d1bffbeb69f5ce52d31
Contents?: true
Size: 898 Bytes
Versions: 18
Compression:
Stored size: 898 Bytes
Contents
module Superstore 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 Superstore::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 Superstore::RecordNotFound, "Couldn't find #{self.name} with key #{id.inspect}" elsif record = where_ids(id).first record else raise Superstore::RecordNotFound end end def find_some(ids) ids = ids.flatten return [] if ids.empty? ids = ids.compact.map(&:to_s).uniq where_ids(ids).to_a end end end end
Version data entries
18 entries across 18 versions & 1 rubygems