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
42 43 44 45 46 47 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 42 def find_many() criteria, = to_query() super.tap do |documents| remove_documents_from_map(documents) if selecting_fields?() end end |
#find_one(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 30 def find_one(={}) criteria, = to_query() 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?() end end end |
#identity_map ⇒ Object
22 23 24 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 22 def identity_map @identity_map ||= {} end |
#identity_map=(v) ⇒ Object
26 27 28 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 26 def identity_map=(v) @identity_map = v end |
#identity_map_off ⇒ Object
68 69 70 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 68 def identity_map_off @identity_map_status = false end |
#identity_map_off? ⇒ Boolean
76 77 78 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 76 def identity_map_off? !identity_map_on? end |
#identity_map_on ⇒ Object
64 65 66 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 64 def identity_map_on @identity_map_status = true end |
#identity_map_on? ⇒ Boolean
72 73 74 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 72 def identity_map_on? identity_map_status end |
#identity_map_status ⇒ Object
60 61 62 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 60 def identity_map_status defined?(@identity_map_status) ? @identity_map_status : true end |
#inherited(descendant) ⇒ Object
17 18 19 20 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 17 def inherited(descendant) descendant.identity_map = identity_map super end |
#load(attrs) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 49 def load(attrs) 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
80 81 82 83 84 85 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 80 def without_identity_map(&block) identity_map_off yield ensure identity_map_on end |