module Croesus::Querying::ClassMethods
Public Instance Methods
key?(id, options = nil)
click to toggle source
# File lib/croesus/querying.rb, line 41 def key?(id, options = nil) { id: id, options: options, model: self } end
Also aliased as: has_key?
load(id, attrs)
click to toggle source
# File lib/croesus/querying.rb, line 46 def load(id, attrs) attrs ||= {} instance = constant_from_attrs(attrs).allocate instance.initialize_from_database(attrs.update('id' => id)) end
read(id, options = nil)
click to toggle source
# File lib/croesus/querying.rb, line 23 def read(id, options = nil) { id: id, options: options, model: self, hit: false } end
read!(id, options = nil)
click to toggle source
# File lib/croesus/querying.rb, line 29 def read!(id, options = nil) read(id, options) || raise(NotFound.new(id)) end
read_multiple(ids, options = nil)
click to toggle source
# File lib/croesus/querying.rb, line 35 def read_multiple(ids, options = nil) { ids: ids, options: options, model: self, hits: 0, misses: 0 } end
Also aliased as: get_multiple, find_multiple
Private Instance Methods
constant_from_attrs(attrs)
click to toggle source
# File lib/croesus/querying.rb, line 52 def constant_from_attrs(attrs) self if attrs.nil? type = attrs[:type] || attrs['type'] self if type.nil? type.constantize rescue NameError self end