bemi-rails 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +1 -1
- data/lib/bemi/context.rb +36 -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: f19aaf859eda061205bee3a1a49aa3985982a80ebb90b94fb44160431753f058
|
4
|
+
data.tar.gz: 947da8058a12c7171e312dc8a2069e6b303b16af670247c287830336def82dad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe752060e2291a4e39cf126a5984a4453db821055e49a80d81e4efd4dfc0d96717d4a6ebdf18cc3800869409438e81bac1b291292497c0c8412d4eb5df9417a6
|
7
|
+
data.tar.gz: 238dfc3d2ed1ce9a0aa6fbdcbf0697009dcd1a29b6858aa01b7518751d3ac0da36e84637b6945c22ca63e6eaf0971aaa1e52981dbb8b8a479d0bf6b8b0800cd4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
#### [v0.2.1](https://github.com/BemiHQ/bemi-rails/compare/v0.2.0...v0.2.1) - 2024-04-16
|
2
|
+
|
3
|
+
- Validate context type to make sure it's a hash or hash-like object
|
4
|
+
|
5
|
+
#### [v0.2.0](https://github.com/BemiHQ/bemi-rails/compare/v0.1.0...v0.2.0) - 2024-04-16
|
6
|
+
|
7
|
+
- Fix compatibility with ActiveRecord versions prior to 7.1
|
8
|
+
- Validate context size to keep it under 1MB
|
9
|
+
|
1
10
|
#### v0.1.0 - 2024-03-08
|
2
11
|
|
3
12
|
- Create the gem
|
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,46 @@
|
|
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
|
+
return if context.nil?
|
41
|
+
return if !context.is_a?(Hash) && !context.respond_to?(:has_key?)
|
42
|
+
|
43
|
+
result = context.to_json
|
44
|
+
result if result.size <= MAX_CONTEXT_SIZE
|
45
|
+
end
|
22
46
|
end
|
23
47
|
end
|
24
48
|
|
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.1
|
4
|
+
version: 0.2.1
|
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
|