Class: Whodunit::Chronicles::Ledger

Inherits:
Object
  • Object
show all
Defined in:
lib/whodunit/chronicles/ledger.rb,
sig/whodunit/chronicles/ledger.rbs

Overview

Base class for append-only audit ledgers.

Ledger is the minimal storage contract consumed by Chronicler. Concrete ledgers only need to implement #append; preparation, indexing, and partitioning are optional capabilities with safe defaults.

Instance Method Summary collapse

Instance Method Details

#append(_entry) ⇒ Object

Append an immutable entry to the ledger.

Parameters:

Returns:

  • (Object)

    implementation-defined result

Raises:

  • (NotImplementedError)

    when not implemented by a concrete ledger



64
65
66
# File 'lib/whodunit/chronicles/ledger.rb', line 64

def append(_entry)
  raise NotImplementedError, "#{self.class} must implement #append"
end

#ensure_indexes!Ledger

Ensure useful indexes if the ledger supports index management.

Returns:



21
22
23
# File 'lib/whodunit/chronicles/ledger.rb', line 21

def ensure_indexes!
  self
end

#migrate!Ledger

Apply storage evolution steps if the ledger supports migrations.

Returns:



28
29
30
31
32
# File 'lib/whodunit/chronicles/ledger.rb', line 28

def migrate!
  prepare!
  ensure_indexes!
  self
end

#partition_for(_entry) ⇒ Ledger

Return the target ledger for an entry.

Partition-aware ledgers override this method. Simple ledgers return themselves.

Parameters:

Returns:

  • (Ledger)

    ledger that should receive the entry



55
56
57
# File 'lib/whodunit/chronicles/ledger.rb', line 55

def partition_for(_entry)
  self
end

#prepare!Ledger

Prepare backing storage if the ledger supports schema creation.

Returns:



14
15
16
# File 'lib/whodunit/chronicles/ledger.rb', line 14

def prepare!
  self
end

#statusHash<Symbol, Object>

Return lightweight operational status for this ledger.

Returns:

  • (Hash<Symbol, Object>)

    ledger status



44
45
46
# File 'lib/whodunit/chronicles/ledger.rb', line 44

def status
  { adapter: self.class.name, ready: verify }
end

#verifyBoolean

Verify that the ledger is operational.

Returns:

  • (Boolean)

    true when the ledger appears usable



37
38
39
# File 'lib/whodunit/chronicles/ledger.rb', line 37

def verify
  true
end