Class: Sfn::IdentityMap

Inherits:
Object
  • Object
show all
Defined in:
lib/satisfaction/identity_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIdentityMap

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

#pagesObject (readonly)

Returns the value of attribute pages.



2
3
4
# File 'lib/satisfaction/identity_map.rb', line 2

def pages
  @pages
end

#recordsObject (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