lookback 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/lib/lookback/backends.rb +75 -0
- data/lib/lookback/version.rb +5 -0
- data/lib/lookback.rb +54 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 43cdcc71110782804391f2157ad0774dcf3f79d98f8cae47ebe76854c3cfbf3f
|
|
4
|
+
data.tar.gz: 863261fa123f9a054d9347badb1ea3f744cedb125786bbf603e3d3306ed561fc
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1039bd84ca6c688cdf3c411d14be8f819425d147a692d345ce4d0471bf9659706686603a31944a94e0044b5aaa3000d26d4637f48c64d3f1618a5e508ba630c4
|
|
7
|
+
data.tar.gz: da8fdb1a15bf80cc530f472845d2734211eb59e4aae8b33c0d73a3b9f87f5d3c5778075af1a12263d643ac2610e44278dd97076def6869d330f5b3b251483e23
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pierre Senechal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Lookback
|
|
2
|
+
|
|
3
|
+
Historical record management for Ruby. **Under active development** — the
|
|
4
|
+
public API may change until a `1.0` release.
|
|
5
|
+
|
|
6
|
+
Lookback records and reads versions of application state. The `0.0.x` line
|
|
7
|
+
ships a working in-memory snapshot backend and the public API surface
|
|
8
|
+
intended to cover future backends:
|
|
9
|
+
|
|
10
|
+
- Native snapshot store (persistent) — planned
|
|
11
|
+
- Ruby PaperTrail adapter — planned
|
|
12
|
+
- Hibernate Envers adapter (over shared datastores) — planned
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
require "lookback"
|
|
18
|
+
|
|
19
|
+
Lookback.track("Order", 42, { status: "pending" }, event: :create)
|
|
20
|
+
Lookback.track("Order", 42, { status: "paid" }, event: :update)
|
|
21
|
+
|
|
22
|
+
Lookback.history("Order", 42).map(&:event) # => [:create, :update]
|
|
23
|
+
Lookback.latest("Order", 42).attributes # => { status: "paid" }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Swap the backend by assigning `Lookback.backend = MyBackend.new`. A backend
|
|
27
|
+
implements `#record(key, attributes, event:, now:)`, `#history(key)`, and
|
|
28
|
+
`#latest(key)`.
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT. See `LICENSE.txt`.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lookback
|
|
4
|
+
module Backends
|
|
5
|
+
# In-memory snapshot backend. Stores an ordered list of versions per
|
|
6
|
+
# (record_class, record_id) key. Suitable for tests and single-process use;
|
|
7
|
+
# persistent stores land in later releases.
|
|
8
|
+
class Snapshot
|
|
9
|
+
Version = Struct.new(:number, :recorded_at, :attributes, :event, keyword_init: true) do
|
|
10
|
+
def to_h = { number: number, recorded_at: recorded_at, attributes: attributes, event: event }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize
|
|
14
|
+
@versions = Hash.new { |h, k| h[k] = [] }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def record(key, attributes, event: :update, now: Time.now)
|
|
18
|
+
list = @versions[key]
|
|
19
|
+
version = Version.new(
|
|
20
|
+
number: list.length + 1,
|
|
21
|
+
recorded_at: now,
|
|
22
|
+
attributes: deep_dup(attributes),
|
|
23
|
+
event: event,
|
|
24
|
+
)
|
|
25
|
+
list << version
|
|
26
|
+
version
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def history(key)
|
|
30
|
+
@versions[key].dup
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def latest(key)
|
|
34
|
+
@versions[key].last
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def clear
|
|
38
|
+
@versions.clear
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def deep_dup(obj)
|
|
44
|
+
case obj
|
|
45
|
+
when Hash then obj.each_with_object({}) { |(k, v), h| h[k] = deep_dup(v) }
|
|
46
|
+
when Array then obj.map { |v| deep_dup(v) }
|
|
47
|
+
else obj.dup rescue obj
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Adapter over Ruby PaperTrail. Not implemented in this release.
|
|
53
|
+
class PaperTrail
|
|
54
|
+
def record(*, **)
|
|
55
|
+
raise Lookback::NotImplementedError, "PaperTrail adapter is under development"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def history(*)
|
|
59
|
+
raise Lookback::NotImplementedError, "PaperTrail adapter is under development"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Adapter over Hibernate Envers (via shared datastore). Not implemented in
|
|
64
|
+
# this release.
|
|
65
|
+
class Envers
|
|
66
|
+
def record(*, **)
|
|
67
|
+
raise Lookback::NotImplementedError, "Envers adapter is under development"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def history(*)
|
|
71
|
+
raise Lookback::NotImplementedError, "Envers adapter is under development"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
data/lib/lookback.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lookback/version"
|
|
4
|
+
require_relative "lookback/backends"
|
|
5
|
+
|
|
6
|
+
# Lookback — historical record management for Ruby.
|
|
7
|
+
#
|
|
8
|
+
# This gem is under active development. The `0.0.x` line ships a working
|
|
9
|
+
# in-memory snapshot backend and the public API surface intended to cover
|
|
10
|
+
# future backends (Ruby PaperTrail, Hibernate Envers, and a persistent native
|
|
11
|
+
# snapshot store). The public API may change until a `1.0` release.
|
|
12
|
+
#
|
|
13
|
+
# Basic usage:
|
|
14
|
+
#
|
|
15
|
+
# Lookback.track("Order", 42, { status: "pending" }, event: :create)
|
|
16
|
+
# Lookback.track("Order", 42, { status: "paid" }, event: :update)
|
|
17
|
+
# Lookback.history("Order", 42).map(&:event) # => [:create, :update]
|
|
18
|
+
# Lookback.latest("Order", 42).attributes # => { status: "paid" }
|
|
19
|
+
module Lookback
|
|
20
|
+
class Error < StandardError; end
|
|
21
|
+
class NotImplementedError < Error; end
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
attr_writer :backend
|
|
25
|
+
|
|
26
|
+
def backend
|
|
27
|
+
@backend ||= Backends::Snapshot.new
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def track(record_type, record_id, attributes, event: :update, now: Time.now)
|
|
31
|
+
backend.record([record_type.to_s, record_id], attributes, event: event, now: now)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def history(record_type, record_id)
|
|
35
|
+
backend.history([record_type.to_s, record_id])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def latest(record_type, record_id)
|
|
39
|
+
backend.latest([record_type.to_s, record_id])
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def reset!
|
|
43
|
+
backend.respond_to?(:clear) ? backend.clear : (@backend = nil)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def api_version
|
|
47
|
+
VERSION
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def supported_backends
|
|
51
|
+
%i[snapshot papertrail envers].freeze
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lookback
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Pierre Senechal
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-07-12 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Lookback defines the interface for a Ruby gem that manages historical
|
|
14
|
+
records and audit snapshots. This release publishes the API surface; backend adapters
|
|
15
|
+
(Envers, PaperTrail, native snapshot store) are under development.
|
|
16
|
+
email:
|
|
17
|
+
- psenechal@wealthsimple.com
|
|
18
|
+
executables: []
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files: []
|
|
21
|
+
files:
|
|
22
|
+
- LICENSE.txt
|
|
23
|
+
- README.md
|
|
24
|
+
- lib/lookback.rb
|
|
25
|
+
- lib/lookback/backends.rb
|
|
26
|
+
- lib/lookback/version.rb
|
|
27
|
+
homepage: https://github.com/psenechal-ws/lookback
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata:
|
|
31
|
+
homepage_uri: https://github.com/psenechal-ws/lookback
|
|
32
|
+
source_code_uri: https://github.com/psenechal-ws/lookback
|
|
33
|
+
post_install_message:
|
|
34
|
+
rdoc_options: []
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '3.2'
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubygems_version: 3.5.22
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: API surface for a Ruby historical-record management gem.
|
|
52
|
+
test_files: []
|