Module: MongoMapper::Plugins::IdentityMap::ClassMethods
- Defined in:
- lib/mongo_mapper/plugins/identity_map.rb
Instance Method Summary collapse
- #find_many(options) ⇒ Object
- #find_one(options = {}) ⇒ Object
- #identity_map ⇒ Object
- #identity_map=(v) ⇒ Object
- #identity_map_off ⇒ Object
- #identity_map_off? ⇒ Boolean
- #identity_map_on ⇒ Object
- #identity_map_on? ⇒ Boolean
- #identity_map_status ⇒ Object
- #inherited(descendant) ⇒ Object
- #load(attrs) ⇒ Object
- #without_identity_map(&block) ⇒ Object
Instance Method Details
#find_many(options) ⇒ Object
44 45 46 47 48 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 44 def find_many() super.tap do |documents| remove_documents_from_map(documents) if selecting_fields?(query().) end end |
#find_one(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 31 def find_one(={}) query = query() criteria = query.criteria.to_hash if simple_find?(criteria) && identity_map.key?(criteria[:_id]) identity_map[criteria[:_id]] else super.tap do |document| remove_documents_from_map(document) if selecting_fields?(query.) end end end |
#identity_map ⇒ Object
23 24 25 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 23 def identity_map @identity_map ||= {} end |
#identity_map=(v) ⇒ Object
27 28 29 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 27 def identity_map=(v) @identity_map = v end |
#identity_map_off ⇒ Object
70 71 72 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 70 def identity_map_off @identity_map_status = false end |
#identity_map_off? ⇒ Boolean
78 79 80 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 78 def identity_map_off? !identity_map_on? end |
#identity_map_on ⇒ Object
66 67 68 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 66 def identity_map_on @identity_map_status = true end |
#identity_map_on? ⇒ Boolean
74 75 76 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 74 def identity_map_on? identity_map_status end |
#identity_map_status ⇒ Object
62 63 64 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 62 def identity_map_status defined?(@identity_map_status) ? @identity_map_status : true end |
#inherited(descendant) ⇒ Object
18 19 20 21 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 18 def inherited(descendant) descendant.identity_map = identity_map super end |
#load(attrs) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 50 def load(attrs) return nil if attrs.nil? document = identity_map[attrs['_id']] if document.nil? || identity_map_off? document = super identity_map[document._id] = document if identity_map_on? end document end |
#without_identity_map(&block) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 82 def without_identity_map(&block) identity_map_off yield ensure identity_map_on end |