bemi-rails 0.2.1 → 0.3.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 +8 -0
- data/lib/bemi/change_query_helpers.rb +39 -0
- data/lib/bemi/record_query_helpers.rb +24 -0
- data/lib/bemi/version.rb +1 -1
- data/lib/bemi.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a06ff1246ab3897a88169b8cad1bc69b1558bf6bb0d00d88408a88c6685fca3c
|
4
|
+
data.tar.gz: 52a82309d53e22acc15f374d152fbf473f4011a0d3c1a20d713e1060e418a470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd7cbe37593d41d81ddaa9e36eb36518ee0c431b96f8ecdadd4fe6ef1d13bb8eaacdd81762aa0d00b949183e215fdcc6cb2a1e8c9616e9d65d6ada156b1847ef
|
7
|
+
data.tar.gz: 79cbc5dcafbe7cc3c6d26e68551031a70a03e12cd636e02edb122014a0e3449c87a233f94fd653cdb4ff577b0ac33fd7bb37b24dc9e863cb507df29a1cb986e8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
#### [v0.3.0](https://github.com/BemiHQ/bemi-rails/compare/v0.2.1...v0.3.0) - 2024-04-26
|
2
|
+
|
3
|
+
- Allow querying changes by a record
|
4
|
+
- Allow filtering changes by values and operations
|
5
|
+
- Allow sorting changes by using new scopes
|
6
|
+
- Allow diffing a change
|
7
|
+
- Filter logs by using `Rails.application.config.filter_parameters`
|
8
|
+
|
1
9
|
#### [v0.2.1](https://github.com/BemiHQ/bemi-rails/compare/v0.2.0...v0.2.1) - 2024-04-16
|
2
10
|
|
3
11
|
- Validate context type to make sure it's a hash or hash-like object
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
5
|
+
module Bemi::ChangeQueryHelpers
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
scope :before, ->(hash) { where('before @> ?', hash.to_json) }
|
10
|
+
scope :after, ->(hash) { where('after @> ?', hash.to_json) }
|
11
|
+
scope :context, ->(hash) { where('context @> ?', hash.to_json) }
|
12
|
+
|
13
|
+
scope :created, -> { where(operation: 'CREATE') }
|
14
|
+
scope :updated, -> { where(operation: 'UPDATE') }
|
15
|
+
scope :deleted, -> { where(operation: 'DELETE') }
|
16
|
+
|
17
|
+
scope :asc, -> { order(committed_at: :asc) }
|
18
|
+
scope :desc, -> { order(committed_at: :desc) }
|
19
|
+
|
20
|
+
self.filter_attributes = (Rails.respond_to?(:filter_parameters) ? Rails.configuration.filter_parameters : []).map do |filter|
|
21
|
+
if filter == :_key
|
22
|
+
/(?<!primary_)key/ # don't filter out primary_key
|
23
|
+
else
|
24
|
+
filter
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def diff
|
30
|
+
result = {}
|
31
|
+
|
32
|
+
(before.keys | after.keys).each do |key|
|
33
|
+
next if before[key] == after[key]
|
34
|
+
result[key] = [before[key], after[key]]
|
35
|
+
end
|
36
|
+
|
37
|
+
result
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
5
|
+
module Bemi::RecordQueryHelpers
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
# Setter
|
10
|
+
def bemi_change_class(bemi_change_class_name)
|
11
|
+
@@bemi_change_class_name = bemi_change_class_name
|
12
|
+
end
|
13
|
+
|
14
|
+
# Getter
|
15
|
+
def __bemi_change_class
|
16
|
+
raise "Please set the change class name with `bemi_change_class 'BemiChange'`" if !@@bemi_change_class_name
|
17
|
+
@@__bemi_change_class ||= @@bemi_change_class_name.constantize
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def bemi_changes
|
22
|
+
self.class.__bemi_change_class.where(table: self.class.table_name, primary_key: attributes[self.class.primary_key])
|
23
|
+
end
|
24
|
+
end
|
data/lib/bemi/version.rb
CHANGED
data/lib/bemi.rb
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
class Bemi
|
4
4
|
end
|
5
5
|
|
6
|
+
require_relative "./bemi/change_query_helpers"
|
6
7
|
require_relative "./bemi/context"
|
7
8
|
require_relative "./bemi/migration"
|
8
9
|
require_relative "./bemi/migration_generator"
|
10
|
+
require_relative "./bemi/record_query_helpers"
|
9
11
|
require_relative "./bemi/version"
|
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.3.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-04-
|
11
|
+
date: 2024-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -53,9 +53,11 @@ files:
|
|
53
53
|
- bemi-rails.gemspec
|
54
54
|
- lib/bemi-rails.rb
|
55
55
|
- lib/bemi.rb
|
56
|
+
- lib/bemi/change_query_helpers.rb
|
56
57
|
- lib/bemi/context.rb
|
57
58
|
- lib/bemi/migration.rb
|
58
59
|
- lib/bemi/migration_generator.rb
|
60
|
+
- lib/bemi/record_query_helpers.rb
|
59
61
|
- lib/bemi/templates/migration.rb.erb
|
60
62
|
- lib/bemi/version.rb
|
61
63
|
- sig/bemi-rails.rbs
|