module Croesus::IdentityMap
Public Class Methods
clear()
click to toggle source
# File lib/croesus/identity_map.rb, line 38 def self.clear repository.clear end
enabled()
click to toggle source
# File lib/croesus/identity_map.rb, line 26 def self.enabled Thread.current[:identity_map_enabled] end
enabled=(flag)
click to toggle source
# File lib/croesus/identity_map.rb, line 22 def self.enabled=(flag) Thread.current[:identity_map_enabled] = flag end
enabled?()
click to toggle source
# File lib/croesus/identity_map.rb, line 30 def self.enabled? enabled == true end
include?(object)
click to toggle source
# File lib/croesus/identity_map.rb, line 42 def self.include?(object) repository.keys.include?(object.id) end
repository()
click to toggle source
# File lib/croesus/identity_map.rb, line 34 def self.repository Thread.current[:identity_map] ||= {} end
use() { || ... }
click to toggle source
# File lib/croesus/identity_map.rb, line 46 def self.use old, self.enabled = enabled, true yield if block_given? ensure self.enabled = old clear end
without() { || ... }
click to toggle source
# File lib/croesus/identity_map.rb, line 55 def self.without old, self.enabled = enabled, false yield if block_given? ensure self.enabled = old end
Public Instance Methods
add_to_identity_map()
click to toggle source
# File lib/croesus/identity_map.rb, line 90 def add_to_identity_map IdentityMap.repository[id] = self if IdentityMap.enabled? end
delete()
click to toggle source
Calls superclass method
# File lib/croesus/identity_map.rb, line 86 def delete super.tap { remove_from_identity_map } end
remove_from_identity_map()
click to toggle source
# File lib/croesus/identity_map.rb, line 94 def remove_from_identity_map IdentityMap.repository.delete(id) if IdentityMap.enabled? end
save(options={})
click to toggle source
Calls superclass method
# File lib/croesus/identity_map.rb, line 82 def save(options={}) super.tap { |result| add_to_identity_map if result } end