bemi-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/bemi/context.rb +33 -12
- data/lib/bemi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa3333de9e0a741dd9ea055875b359e3cc5762e0cb8cda2ca7993fb013e761ad
|
4
|
+
data.tar.gz: 24080ca04dee07312adb7e41bf08286aae441ec404fc8bc1d06ed64693041c27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d927d26dc83bdc1d1d0f44353506729c885b2de498f077fda655556f76ca14fb6dde5fb01f0c72e9f4a372e7970510bc9f16b4f60066539e0fe2bc3325259c77
|
7
|
+
data.tar.gz: ba9d3e21f4d365e4dc419a6444fe3fddfe8bd98e753eb08f24064be20d3883e864d514ab2cc89b050657410a835c4fdfebed82ac0cdaa44f7f154d3081eb7d35
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
# Bemi Rails
|
26
26
|
|
27
|
-
[Bemi](https://bemi.io) plugs into [Ruby on Rails](https://github.com/rails/rails) with Active Record and PostgreSQL to track
|
27
|
+
[Bemi](https://bemi.io) plugs into [Ruby on Rails](https://github.com/rails/rails) with Active Record and your existing PostgreSQL database to track data changes automatically. It unlocks robust context-aware audit trails and time travel querying inside your application.
|
28
28
|
|
29
29
|
Designed with simplicity and non-invasiveness in mind, Bemi doesn't require any alterations to your existing database structure. It operates in the background, empowering you with data change tracking features.
|
30
30
|
|
data/lib/bemi/context.rb
CHANGED
@@ -3,22 +3,43 @@
|
|
3
3
|
require 'active_record'
|
4
4
|
|
5
5
|
class Bemi
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
7
|
+
:close, :declare, :fetch, :move, :set, :show
|
8
|
+
)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
MAX_CONTEXT_SIZE = 1_000_000 # ~1MB
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def set_context(ctx)
|
14
|
+
Thread.current[:bemi_context] = ctx
|
15
|
+
end
|
16
|
+
|
17
|
+
def context
|
18
|
+
Thread.current[:bemi_context]
|
19
|
+
end
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
def append_context
|
22
|
+
Proc.new do |sql, adapter = nil| # Adapter is automatically passed only with Rails v7.1+
|
23
|
+
if (adapter ? adapter.write_query?(sql) : write_query?(sql)) && ctx = serialized_context
|
24
|
+
"#{sql} /*Bemi #{ctx} Bemi*/"
|
25
|
+
else
|
26
|
+
sql
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def write_query?(sql)
|
34
|
+
!READ_QUERY.match?(sql)
|
35
|
+
rescue ArgumentError
|
36
|
+
!READ_QUERY.match?(sql.b)
|
37
|
+
end
|
38
|
+
|
39
|
+
def serialized_context
|
40
|
+
result = context.to_json
|
41
|
+
result if result.size <= MAX_CONTEXT_SIZE
|
42
|
+
end
|
22
43
|
end
|
23
44
|
end
|
24
45
|
|
data/lib/bemi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bemi-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- exAspArk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|