Class: Perpetuity::DirtyTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/perpetuity/dirty_tracker.rb

Instance Method Summary collapse

Constructor Details

#initializeDirtyTracker

Returns a new instance of DirtyTracker.



5
6
7
# File 'lib/perpetuity/dirty_tracker.rb', line 5

def initialize
  @map = Hash.new { |hash, key| hash[key] = {} }
end

Instance Method Details

#<<(object) ⇒ Object



13
14
15
16
17
# File 'lib/perpetuity/dirty_tracker.rb', line 13

def << object
  klass = object.class
  id = object.instance_variable_get(:@id)
  @map[klass][id.to_s] = object.dup
end

#[](klass, id) ⇒ Object



9
10
11
# File 'lib/perpetuity/dirty_tracker.rb', line 9

def [] klass, id
  @map[klass][id.to_s]
end