Module: Snappier::Replay

Defined in:
lib/snappier/replay.rb

Class Method Summary collapse

Class Method Details

.for(type:, id:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/snappier/replay.rb', line 8

def self.for(type:, id:)
  previous_state = {}

  Registry.persistence.each(type: type, id: id) do |current|
    content = current.delete(:content)
    current[:who] = content.delete("who")
    current[:state] = content.delete("state")
    current[:changes] = Changes.between(previous_state, current[:state])

    yield(current)

    previous_state = current[:state]
  end
end

.for_entity(entity) ⇒ Object



23
24
25
# File 'lib/snappier/replay.rb', line 23

def self.for_entity(entity)
  self.for(type: entity.class.name, id: entity.id)
end