Module: Lookback

Defined in:
lib/lookback.rb,
lib/lookback/version.rb,
lib/lookback/backends.rb

Overview

Lookback — historical record management for Ruby.

This gem is under active development. The 0.0.x line ships a working in-memory snapshot backend and the public API surface intended to cover future backends (Ruby PaperTrail, Hibernate Envers, and a persistent native snapshot store). The public API may change until a 1.0 release.

Basic usage:

Lookback.track("Order", 42, { status: "pending" }, event: :create)
Lookback.track("Order", 42, { status: "paid"    }, event: :update)
Lookback.history("Order", 42).map(&:event)  # => [:create, :update]
Lookback.latest("Order", 42).attributes     # => { status: "paid" }

Defined Under Namespace

Modules: Backends Classes: Error, NotImplementedError

Constant Summary collapse

VERSION =
"0.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.backendObject



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

def backend
  @backend ||= Backends::Snapshot.new
end

Class Method Details

.api_versionObject



46
47
48
# File 'lib/lookback.rb', line 46

def api_version
  VERSION
end

.history(record_type, record_id) ⇒ Object



34
35
36
# File 'lib/lookback.rb', line 34

def history(record_type, record_id)
  backend.history([record_type.to_s, record_id])
end

.latest(record_type, record_id) ⇒ Object



38
39
40
# File 'lib/lookback.rb', line 38

def latest(record_type, record_id)
  backend.latest([record_type.to_s, record_id])
end

.reset!Object



42
43
44
# File 'lib/lookback.rb', line 42

def reset!
  backend.respond_to?(:clear) ? backend.clear : (@backend = nil)
end

.supported_backendsObject



50
51
52
# File 'lib/lookback.rb', line 50

def supported_backends
  %i[snapshot papertrail envers].freeze
end

.track(record_type, record_id, attributes, event: :update, now: Time.now) ⇒ Object



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

def track(record_type, record_id, attributes, event: :update, now: Time.now)
  backend.record([record_type.to_s, record_id], attributes, event: event, now: now)
end