Class: Mongoo::IdentityMap
- Inherits:
-
Object
- Object
- Mongoo::IdentityMap
- Defined in:
- lib/mongoo/identity_map.rb
Class Method Summary collapse
- .flush! ⇒ Object
- .off! ⇒ Object
- .off? ⇒ Boolean
- .on! ⇒ Object
- .on? ⇒ Boolean
- .read(id) ⇒ Object
- .simple_query?(query, opts) ⇒ Boolean
- .store ⇒ Object
- .write(doc) ⇒ Object
Class Method Details
.flush! ⇒ Object
56 57 58 59 60 61 |
# File 'lib/mongoo/identity_map.rb', line 56 def flush! if store Thread.current[:mongoo][:identity_map][:store] = {} true end end |
.off! ⇒ Object
14 15 16 17 18 19 |
# File 'lib/mongoo/identity_map.rb', line 14 def off! @on = false if Thread.current[:mongoo] Thread.current[:mongoo][:identity_map] = nil end; true end |
.off? ⇒ Boolean
21 22 23 |
# File 'lib/mongoo/identity_map.rb', line 21 def off? @on == false end |
.on! ⇒ Object
6 7 8 |
# File 'lib/mongoo/identity_map.rb', line 6 def on! @on = true end |
.on? ⇒ Boolean
10 11 12 |
# File 'lib/mongoo/identity_map.rb', line 10 def on? @on == true end |
.read(id) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/mongoo/identity_map.rb', line 40 def read(id) if store if id.is_a?(BSON::ObjectId) store[id.to_s] elsif id.is_a?(Hash) store[(id[:_id] || id["_id"]).to_s] end end end |
.simple_query?(query, opts) ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/mongoo/identity_map.rb', line 32 def simple_query?(query, opts) return false if query.nil? return false unless opts.blank? return true if query.is_a?(BSON::ObjectId) return true if [[:_id], ["_id"]].include?(query.keys) false end |
.store ⇒ Object
25 26 27 28 29 30 |
# File 'lib/mongoo/identity_map.rb', line 25 def store return nil unless on? Thread.current[:mongoo] ||= {} Thread.current[:mongoo][:identity_map] ||= {} Thread.current[:mongoo][:identity_map][:store] ||= {} end |
.write(doc) ⇒ Object
50 51 52 53 54 |
# File 'lib/mongoo/identity_map.rb', line 50 def write(doc) if store && !store.has_key?(doc.id.to_s) store[doc.id.to_s] = doc end end |