Class: Sandals::SnapshotHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/sandals/snapshot_history.rb

Defined Under Namespace

Classes: Snapshot

Instance Method Summary collapse

Constructor Details

#initializeSnapshotHistory

Returns a new instance of SnapshotHistory.



7
8
9
10
# File 'lib/sandals/snapshot_history.rb', line 7

def initialize
  @revision = 0
  @snapshots = []
end

Instance Method Details

#currentObject



26
27
28
# File 'lib/sandals/snapshot_history.rb', line 26

def current
  @snapshots.last
end

#discard_before(revision) ⇒ Object



30
31
32
# File 'lib/sandals/snapshot_history.rb', line 30

def discard_before(revision)
  @snapshots.reject! { |snapshot| snapshot.revision < revision }
end

#fetch(revision) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
# File 'lib/sandals/snapshot_history.rb', line 19

def fetch(revision)
  snapshot = @snapshots.find { |candidate| candidate.revision == revision }
  return snapshot if snapshot

  raise ArgumentError, "unknown revision: #{revision}"
end

#publish(view, controls:) ⇒ Object



12
13
14
15
16
17
# File 'lib/sandals/snapshot_history.rb', line 12

def publish(view, controls:)
  @revision += 1
  snapshot = Snapshot.new(@revision, view, controls)
  @snapshots << snapshot
  snapshot
end