bemi-rails 0.2.1 → 0.4.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 +12 -0
- data/lib/bemi/change_query_helpers.rb +42 -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: 034d1786960dc8bf127bed6990eda216051465f6bbebc1c945aeb2657877c70a
|
4
|
+
data.tar.gz: fa18ebcf1977a3806a87f184bd542766c56f26e9689d4c50dc017a55ac190d32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0846a99d796f74d54d4a0f4ae69107895ba1621e11f3ca33afddb5f598b23eee6375be68ef076a58295b4d3bf85abc3a5e38756c5c5570bc5c593b6d8f0f5f6
|
7
|
+
data.tar.gz: 0aed91366aa8245cf97f0d87043c4c7b0686c45e8f661f6a7c3fe658ac49dc36cf65656073a37d70c14a8bb0361c3d6c978b33ae1d44e839553aa043d7093ea1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
#### [v0.4.0](https://github.com/BemiHQ/bemi-rails/compare/v0.3.0...v0.4.0) - 2024-04-26
|
2
|
+
|
3
|
+
- Allow filtering changes by values with negative matching
|
4
|
+
|
5
|
+
#### [v0.3.0](https://github.com/BemiHQ/bemi-rails/compare/v0.2.1...v0.3.0) - 2024-04-26
|
6
|
+
|
7
|
+
- Allow querying changes by a record
|
8
|
+
- Allow filtering changes by values and operations
|
9
|
+
- Allow sorting changes by using new scopes
|
10
|
+
- Allow diffing a change
|
11
|
+
- Filter logs by using `Rails.application.config.filter_parameters`
|
12
|
+
|
1
13
|
#### [v0.2.1](https://github.com/BemiHQ/bemi-rails/compare/v0.2.0...v0.2.1) - 2024-04-16
|
2
14
|
|
3
15
|
- Validate context type to make sure it's a hash or hash-like object
|
@@ -0,0 +1,42 @@
|
|
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 :before_not, ->(hash) { where.not('before @> ?', hash.to_json) }
|
11
|
+
scope :after, ->(hash) { where('after @> ?', hash.to_json) }
|
12
|
+
scope :after_not, ->(hash) { where.not('after @> ?', hash.to_json) }
|
13
|
+
scope :context, ->(hash) { where('context @> ?', hash.to_json) }
|
14
|
+
scope :context_not, ->(hash) { where.not('context @> ?', hash.to_json) }
|
15
|
+
|
16
|
+
scope :created, -> { where(operation: 'CREATE') }
|
17
|
+
scope :updated, -> { where(operation: 'UPDATE') }
|
18
|
+
scope :deleted, -> { where(operation: 'DELETE') }
|
19
|
+
|
20
|
+
scope :asc, -> { order(committed_at: :asc) }
|
21
|
+
scope :desc, -> { order(committed_at: :desc) }
|
22
|
+
|
23
|
+
self.filter_attributes = (Rails.respond_to?(:filter_parameters) ? Rails.configuration.filter_parameters : []).map do |filter|
|
24
|
+
if filter == :_key
|
25
|
+
/(?<!primary_)key/ # don't filter out primary_key
|
26
|
+
else
|
27
|
+
filter
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def diff
|
33
|
+
result = {}
|
34
|
+
|
35
|
+
(before.keys | after.keys).each do |key|
|
36
|
+
next if before[key] == after[key]
|
37
|
+
result[key] = [before[key], after[key]]
|
38
|
+
end
|
39
|
+
|
40
|
+
result
|
41
|
+
end
|
42
|
+
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.4.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
|