Class: Sfn::IdentityMap
- Inherits:
-
Object
- Object
- Sfn::IdentityMap
- Defined in:
- lib/satisfaction/identity_map.rb
Instance Attribute Summary collapse
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
- #expire_record(klass, id) ⇒ Object
- #get_record(klass, id, &block) ⇒ Object
-
#initialize ⇒ IdentityMap
constructor
A new instance of IdentityMap.
Constructor Details
#initialize ⇒ IdentityMap
Returns a new instance of IdentityMap.
4 5 6 7 |
# File 'lib/satisfaction/identity_map.rb', line 4 def initialize @records = {} @pages = {} end |
Instance Attribute Details
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
2 3 4 |
# File 'lib/satisfaction/identity_map.rb', line 2 def pages @pages end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
2 3 4 |
# File 'lib/satisfaction/identity_map.rb', line 2 def records @records end |
Instance Method Details
#expire_record(klass, id) ⇒ Object
18 19 20 |
# File 'lib/satisfaction/identity_map.rb', line 18 def expire_record(klass, id) @records[[klass, id]] = nil end |
#get_record(klass, id, &block) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/satisfaction/identity_map.rb', line 9 def get_record(klass, id, &block) result = @records[[klass, id]] result ||= begin obj = yield(klass, id) @records[[klass, id]] = obj end result end |