Module: Dynamoid::IdentityMap::ClassMethods
- Defined in:
- lib/dynamoid/identity_map.rb
Instance Method Summary collapse
- #find_by_id(id, options = {}) ⇒ Object
- #from_database(attrs = {}) ⇒ Object
- #identity_map ⇒ Object
- #identity_map_key(attrs) ⇒ Object
- #identity_map_off? ⇒ Boolean
- #identity_map_on? ⇒ Boolean
Instance Method Details
#find_by_id(id, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dynamoid/identity_map.rb', line 34 def find_by_id(id, = {}) return super if identity_map_off? key = id.to_s if range_key = [:range_key] key += "::#{range_key}" end if identity_map[key] identity_map[key] else super end end |
#from_database(attrs = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dynamoid/identity_map.rb', line 18 def from_database(attrs = {}) return super if identity_map_off? key = identity_map_key(attrs) document = identity_map[key] if document.nil? document = super identity_map[key] = document else document.load(attrs) end document end |
#identity_map ⇒ Object
14 15 16 |
# File 'lib/dynamoid/identity_map.rb', line 14 def identity_map @identity_map ||= {} end |
#identity_map_key(attrs) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/dynamoid/identity_map.rb', line 50 def identity_map_key(attrs) key = attrs[hash_key].to_s if range_key key += "::#{attrs[range_key]}" end key end |
#identity_map_off? ⇒ Boolean
62 63 64 |
# File 'lib/dynamoid/identity_map.rb', line 62 def identity_map_off? !identity_map_on? end |