Class: Eternity::Tracker

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

Constant Summary collapse

Changes =
Restruct::NestedHash.new CollectionTracker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ Tracker

Returns a new instance of Tracker.



11
12
13
14
15
# File 'lib/eternity/tracker.rb', line 11

def initialize(repository)
  @repository = repository
  @changes = Changes.new connection: Eternity.connection, 
                         id: repository.id[:changes]
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



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

def repository
  @repository
end

Instance Method Details

#countObject



17
18
19
20
21
# File 'lib/eternity/tracker.rb', line 17

def count
  changes.inject(0) do |sum, (collection, tracker)|
    sum + tracker.count
  end
end

#flattenObject



26
27
28
29
30
31
# File 'lib/eternity/tracker.rb', line 26

def flatten
  changes.each_with_object({}) do |(collection, tracker), hash|
    collection_changes = tracker.flatten
    hash[collection] = collection_changes unless collection_changes.empty?
  end
end