Class: Eternity::CollectionTracker

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/eternity/collection_tracker.rb

Constant Summary collapse

Changes =
Restruct::NestedHash.new ObjectTracker

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CollectionTracker

Returns a new instance of CollectionTracker.



9
10
11
# File 'lib/eternity/collection_tracker.rb', line 9

def initialize(options)
  @changes = Changes.new options
end

Instance Method Details

#delete(id) ⇒ Object



21
22
23
# File 'lib/eternity/collection_tracker.rb', line 21

def delete(id)
  changes[id].delete
end

#flattenObject



35
36
37
38
39
40
# File 'lib/eternity/collection_tracker.rb', line 35

def flatten
  changes.each_with_object({}) do |(id, tracker), hash|
    change = tracker.flatten
    hash[id] = change if change
  end
end

#insert(id, data) ⇒ Object



13
14
15
# File 'lib/eternity/collection_tracker.rb', line 13

def insert(id, data)
  changes[id].insert data
end

#revert(id) ⇒ Object



25
26
27
# File 'lib/eternity/collection_tracker.rb', line 25

def revert(id)
  changes[id].revert
end

#revert_allObject



29
30
31
32
33
# File 'lib/eternity/collection_tracker.rb', line 29

def revert_all
  locker.lock! :revert_all do
    changes.destroy
  end
end

#update(id, data) ⇒ Object



17
18
19
# File 'lib/eternity/collection_tracker.rb', line 17

def update(id, data)
  changes[id].update data
end