Module: Toy::IdentityMap
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
- .clear ⇒ Object
- .enabled ⇒ Object
- .enabled=(flag) ⇒ Object
- .enabled? ⇒ Boolean
- .include?(object) ⇒ Boolean
- .repository ⇒ Object
- .use ⇒ Object
- .without ⇒ Object
Instance Method Summary collapse
- #add_to_identity_map ⇒ Object
- #delete ⇒ Object
- #remove_from_identity_map ⇒ Object
- #save(options = {}) ⇒ Object
Class Method Details
.clear ⇒ Object
21 22 23 |
# File 'lib/toy/identity_map.rb', line 21 def self.clear repository.clear end |
.enabled ⇒ Object
9 10 11 |
# File 'lib/toy/identity_map.rb', line 9 def self.enabled Thread.current[:toystore_identity_map_enabled] end |
.enabled=(flag) ⇒ Object
5 6 7 |
# File 'lib/toy/identity_map.rb', line 5 def self.enabled=(flag) Thread.current[:toystore_identity_map_enabled] = flag end |
.enabled? ⇒ Boolean
13 14 15 |
# File 'lib/toy/identity_map.rb', line 13 def self.enabled? enabled == true end |
.include?(object) ⇒ Boolean
25 26 27 |
# File 'lib/toy/identity_map.rb', line 25 def self.include?(object) repository.keys.include?(object.id) end |
.repository ⇒ Object
17 18 19 |
# File 'lib/toy/identity_map.rb', line 17 def self.repository Thread.current[:toystore_identity_map] ||= {} end |
.use ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/toy/identity_map.rb', line 29 def self.use old, self.enabled = enabled, true yield if block_given? ensure self.enabled = old clear end |
.without ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/toy/identity_map.rb', line 38 def self.without old, self.enabled = enabled, false yield if block_given? ensure self.enabled = old end |
Instance Method Details
#add_to_identity_map ⇒ Object
73 74 75 |
# File 'lib/toy/identity_map.rb', line 73 def add_to_identity_map IdentityMap.repository[id] = self if IdentityMap.enabled? end |
#delete ⇒ Object
69 70 71 |
# File 'lib/toy/identity_map.rb', line 69 def delete super.tap { remove_from_identity_map } end |
#remove_from_identity_map ⇒ Object
77 78 79 |
# File 'lib/toy/identity_map.rb', line 77 def remove_from_identity_map IdentityMap.repository.delete(id) if IdentityMap.enabled? end |
#save(options = {}) ⇒ Object
65 66 67 |
# File 'lib/toy/identity_map.rb', line 65 def save(={}) super.tap { |result| add_to_identity_map if result } end |