class

Keep::Log

Inherits Reference < Object

The append-only log of commits, as a C0 stream-mode file.

log = Keep::Log.open("book.log") log.append(at: "2026-09-21 16:26", origin: "cli", kind: "ledger", summary: "…") do |c| c.action("record", 41, "2026-09-03", "Market run", "", ["Expenses:Food", "4820", "Assets:Checking", "-4820"]) end log.each_commit(after: 38) { |commit| … } log.fold(state, after: 38) { |state, action| apply(state, action) }

Layout: a preamble block (GS keep/1), then one block per commit — a commit record followed by one record per action — each ended by ETB.

Constructors

new(path : String)
Source
open(path : Path | String) : Log

Open a log, creating it with its preamble if it doesn't exist, and truncating any torn tail left by an interrupted append.

Source

Instance methods

append(at : String, origin : String, kind : String, summary : String, & : Builder -> ) : Commit

Append one commit. Assigns the next sequence number under the lock and writes the block and its ETB as a single append.

Source
commit(seq : Int64) : Commit | Nil
Source
commits

Every commit, in order, with revert marks resolved.

Source
each_commit(after : Int64 = 0, & : Commit -> ) : Nil

Commits after after, in order, revert marks resolved over the whole log.

Source
fold(state : T, after : Int64 = 0, & : T, Action -> ) : Int64 forall T

Apply the actions of every non-reverted, non-mark commit after after to state, in order. Returns the version folded to.

Source
lock

Run the block holding an exclusive advisory lock on the log, so two processes can't assign the same sequence number. Reentrant on the same Log instance (an application holding the lock around append-plus- checkpoint calls append, which locks again). Keep sections short.

Source
path
Source
replay_needed?(after : Int64) : Bool

True if a mark after after targets a commit at or before it — in which case a state folded up to after can't be advanced by applying only later commits; fold from scratch instead.

Source
revert(seq : Int64, at : String, origin : String, kind : String, summary : String) : Commit

Mark seq reverted. Raises if it doesn't exist, is itself a mark, or is already reverted.

Source
unrevert(seq : Int64, at : String, origin : String, kind : String, summary : String) : Commit
Source
version

The sequence of the last commit (0 for an empty log).

Source

Nested types