module Croesus::Querying::ClassMethods

Public Instance Methods

find(id, options = nil)
Alias for: read
find!(id, options = nil)
Alias for: read!
find_multiple(ids, options = nil)
Alias for: read_multiple
get(id, options = nil)
Alias for: read
get!(id, options = nil)
Alias for: read!
get_multiple(ids, options = nil)
Alias for: read_multiple
has_key?(id, options = nil)
Alias for: key?
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
Also aliased as: get, find
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
Also aliased as: get!, find!
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