Module: StorageRoom::IdentityMap
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/storage_room/identity_map.rb
Overview
With inspiration from John Nunemaker’s MongoMapper
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.clear ⇒ Object
14 15 16 |
# File 'lib/storage_room/identity_map.rb', line 14 def self.clear models.each { |m| m.identity_map.clear } end |
.models ⇒ Object
10 11 12 |
# File 'lib/storage_room/identity_map.rb', line 10 def self.models @models ||= ::Set.new end |
Instance Method Details
#create(*args) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/storage_room/identity_map.rb', line 106 def create(*args) if result = super identity_map[self[:@url]] = self if self.class.identity_map_on? end result end |
#destroy ⇒ Object
113 114 115 116 |
# File 'lib/storage_room/identity_map.rb', line 113 def destroy identity_map.delete(self[:@url]) if self.class.identity_map_on? super end |
#identity_map ⇒ Object
97 98 99 |
# File 'lib/storage_room/identity_map.rb', line 97 def identity_map self.class.identity_map end |
#in_identity_map? ⇒ Boolean
101 102 103 104 |
# File 'lib/storage_room/identity_map.rb', line 101 def in_identity_map? return false if self[:@url].blank? identity_map.include?(self[:@url]) end |