Module: Croesus::Querying::ClassMethods

Defined in:
lib/croesus/querying.rb

Instance Method Summary collapse

Instance Method Details

#key?(id, options = nil) ⇒ Boolean Also known as: has_key?

Returns:



41
42
43
# File 'lib/croesus/querying.rb', line 41

def key?(id, options = nil)
  { id: id, options: options, model: self }
end

#load(id, attrs) ⇒ Object



46
47
48
49
50
# 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) ⇒ Object Also known as: get, find



23
24
25
# 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) ⇒ Object Also known as: get!, find!



29
30
31
# 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) ⇒ Object Also known as: get_multiple, find_multiple



35
36
37
# File 'lib/croesus/querying.rb', line 35

def read_multiple(ids, options = nil)
  { ids: ids, options: options, model: self, hits: 0, misses: 0 }
end