Module: Croesus::Querying::ClassMethods
- Defined in:
- lib/croesus/querying.rb
Instance Method Summary collapse
- #key?(id, options = nil) ⇒ Boolean (also: #has_key?)
- #load(id, attrs) ⇒ Object
- #read(id, options = nil) ⇒ Object (also: #get, #find)
- #read!(id, options = nil) ⇒ Object (also: #get!, #find!)
- #read_multiple(ids, options = nil) ⇒ Object (also: #get_multiple, #find_multiple)
Instance Method Details
#key?(id, options = nil) ⇒ Boolean Also known as: has_key?
41 42 43 |
# File 'lib/croesus/querying.rb', line 41 def key?(id, = nil) { id: id, 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, = nil) { id: id, 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, = nil) read(id, ) || 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, = nil) { ids: ids, options: , model: self, hits: 0, misses: 0 } end |