active_record-journal 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +0 -14
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +2 -2
- data/README.md +5 -119
- data/lib/active_record/journal/journable/attributes.rb +7 -1
- data/lib/active_record/journal/journable/context.rb +1 -0
- data/lib/active_record/journal/version.rb +1 -1
- metadata +3 -3
- data/CODE_OF_CONDUCT.md +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b021661495e48089865f294b07b27a8c2916328e26df0449bbdf44ee23e1004b
|
4
|
+
data.tar.gz: d2803f703867441b96bba2ce74a69125984ab12b1d751e75df6572b18651dd20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 174691c8f5d8cf85d2c7437f27b57fa1d3d4e833b8eb8e6d6008d7deb61b297eef6c81afecfaa0c46132d9d540d3f6f08d4d407b9706b29904f93097daae0a31
|
7
|
+
data.tar.gz: 81a0339f9a81796b3365e1ffb166d27d4a3cf751e06ee1b559eff1733f38d4b2b443b20e7785f9896a4da665902cc313100cfb8bb317ba091481b5f824d6cd3d
|
data/.circleci/config.yml
CHANGED
@@ -46,11 +46,6 @@ commands:
|
|
46
46
|
command: bundle install
|
47
47
|
- run: chmod +x bin/setup
|
48
48
|
- run: ./bin/setup
|
49
|
-
rubocop:
|
50
|
-
steps:
|
51
|
-
- run:
|
52
|
-
name: Rubocop
|
53
|
-
command: bundle exec rubocop
|
54
49
|
rspec:
|
55
50
|
steps:
|
56
51
|
- run:
|
@@ -73,12 +68,6 @@ jobs:
|
|
73
68
|
executor: gem
|
74
69
|
steps:
|
75
70
|
- dependencies
|
76
|
-
linter:
|
77
|
-
description: 'Rubocop'
|
78
|
-
executor: gem
|
79
|
-
steps:
|
80
|
-
- dependencies
|
81
|
-
- rubocop
|
82
71
|
specs:
|
83
72
|
description: 'Run specs'
|
84
73
|
parameters:
|
@@ -102,9 +91,6 @@ workflows:
|
|
102
91
|
integration-workflow:
|
103
92
|
jobs:
|
104
93
|
- build
|
105
|
-
- linter:
|
106
|
-
requires:
|
107
|
-
- build
|
108
94
|
- specs:
|
109
95
|
name: postgres-specs
|
110
96
|
db: postgresql
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## \[Unreleased\]
|
8
|
+
|
9
|
+
## \[[0.1.1](https://github.com/mkiroshdz/active_record-journal/compare/v0.1.0...v0.1.1)\] - 2022-03-11
|
10
|
+
### Fixed
|
11
|
+
- [#14](https://github.com/mkiroshdz/active_record-journal/pull/14) Prevents tracking of rails timestamps attributes.
|
12
|
+
- [#15](https://github.com/mkiroshdz/active_record-journal/pull/15) Allow exceptions to bubble up in order to be handled properly.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
[![CircleCI](https://circleci.com/gh/mkiroshdz/active_record-journal/tree/main.svg?style=svg)](https://circleci.com/gh/mkiroshdz/active_record-journal/tree/main)
|
2
|
-
|
3
1
|
# ActiveRecord::Journal
|
4
2
|
|
3
|
+
[![CircleCI](https://circleci.com/gh/mkiroshdz/active_record-journal/tree/main.svg?style=svg)](https://circleci.com/gh/mkiroshdz/active_record-journal/tree/main)
|
4
|
+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/3654af1924a941acb437adb133824ace)](https://www.codacy.com/gh/mkiroshdz/active_record-journal/dashboard?utm_source=github.com&utm_medium=referral&utm_content=mkiroshdz/active_record-journal&utm_campaign=Badge_Grade)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/active_record-journal.svg)](https://badge.fury.io/rb/active_record-journal)
|
6
|
+
|
5
7
|
ActiveRecord::Journal allows you to keep track of the CRUDs on your ActiveRecord models and tag them with the data of your choice (the user or job that triggered the actions, description, ...).
|
6
8
|
|
7
9
|
## Getting started
|
@@ -20,125 +22,9 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
$ gem install active_record-journal
|
22
24
|
|
23
|
-
|
24
|
-
## Setup
|
25
|
-
|
26
|
-
### Initialization
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
ActiveRecord::Journal.configuration.entries_class = 'BookChangeLog'
|
30
|
-
ActiveRecord::Journal.configuration.tags_class = 'BookChangeTag'
|
31
|
-
ActiveRecord::Journal.configuration.autorecording_enabled = true
|
32
|
-
```
|
33
|
-
|
34
|
-
### Logs
|
35
|
-
|
36
|
-
You need to define the models that will persist the records and tags of the CRUDs.
|
37
|
-
|
38
|
-
```ruby
|
39
|
-
class BookChangeLog < ActiveRecord::Base; end
|
40
|
-
class BookChangeTag < ActiveRecord::Base; end
|
41
|
-
```
|
42
|
-
|
43
|
-
The minimun attributes required for the models are shown in this schema:
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
create_table :book_change_logs do |t| # Table for the records
|
47
|
-
# t.string :changes_map
|
48
|
-
t.jsonb :changes_map
|
49
|
-
t.string :action
|
50
|
-
t.string :journable_type
|
51
|
-
t.integer :journable_id
|
52
|
-
t.string :journal_tag_type
|
53
|
-
t.integer :journal_tag_id
|
54
|
-
t.datetime :created_at
|
55
|
-
end
|
56
|
-
|
57
|
-
create_table :book_change_tags do |t| # Table for the tags
|
58
|
-
t.string :journable_type
|
59
|
-
t.integer :journable_id
|
60
|
-
t.datetime :created_at
|
61
|
-
end
|
62
|
-
```
|
63
|
-
|
64
|
-
Note: The gem assumes that the `BookChangeLog#changes_map=` receives a hash and the logic to handle the serialization will be handled by the model regardless of the type of changes_map in the database.
|
65
|
-
|
66
|
-
### Extend ActiveRecord::Base
|
67
|
-
|
68
|
-
This will provide the required methods to enable tracking in the models.
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
class RecordWithLogs < ActiveRecord::Base
|
72
|
-
self.abstract_class = true
|
73
|
-
extend ActiveRecord::Journal::Journable
|
74
|
-
end
|
75
|
-
```
|
76
|
-
|
77
|
-
### Model tracking
|
78
|
-
|
79
|
-
You can use the methods `ActiveRecord::Journal::Journable::journal_writes` and `ActiveRecord::Journal::Journable::journal_reads` to define a set of rules that tell your model how to keep track of the records. Every time a CRUD is triggered all the rules defined are checked and executed if the necessary conditions are met.
|
80
|
-
|
81
|
-
```ruby
|
82
|
-
class Author < RecordWithLogs
|
83
|
-
journal_writes on: %i[create]
|
84
|
-
journal_writes on: %i[update], only: %i[name last_name]
|
85
|
-
end
|
86
|
-
|
87
|
-
class Book < RecordWithLogs
|
88
|
-
belongs_to :author
|
89
|
-
journal_reads unless: :best_seller?
|
90
|
-
journal_reads entries_class: CustomBookChangeLog, tag_class: BookChangeTag, if: :best_seller?
|
91
|
-
journal_writes
|
92
|
-
end
|
93
|
-
```
|
94
|
-
|
95
25
|
## Usage
|
96
26
|
|
97
|
-
|
98
|
-
|
99
|
-
You can create and associate a tag to a group of CRUDS.
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
ActiveRecord::Journal.tag(user: current_user, description: 'Create book') do |tag|
|
103
|
-
tag.actions do
|
104
|
-
author = Author.find_by(id: params[:author_id])
|
105
|
-
Book.create!(title: params[:title], author: author)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
```
|
109
|
-
|
110
|
-
### Ignore operations
|
111
|
-
|
112
|
-
Can ignore actions originally configured to be tracked.
|
113
|
-
|
114
|
-
```ruby
|
115
|
-
ActiveRecord::Journal.ignore do |context|
|
116
|
-
context.actions do
|
117
|
-
author = Author.find_by(id: params[:author_id])
|
118
|
-
Book.create!(title: params[:title], author: author)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
```
|
122
|
-
|
123
|
-
### One time constraints
|
124
|
-
|
125
|
-
```ruby
|
126
|
-
ActiveRecord::Journal.tag(user: current_user) do |tag|
|
127
|
-
tag.record(Book, if: ->(record) { record.author.present? })
|
128
|
-
tag.actions do
|
129
|
-
author = Author.find_by(id: params[:author_id])
|
130
|
-
Book.create!(title: params[:title], author: author)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
ActiveRecord::Journal.context do |context|
|
135
|
-
context.record(Book, unless: ->(record) { record.author.present? })
|
136
|
-
context.actions do
|
137
|
-
author = Author.find_by(id: params[:author_id])
|
138
|
-
Book.create!(title: params[:title], author: author)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
```
|
27
|
+
Check the [wiki](https://github.com/mkiroshdz/active_record-journal/wiki/Index) for usage and configurations.
|
142
28
|
|
143
29
|
## Development
|
144
30
|
|
@@ -27,7 +27,13 @@ module ActiveRecord
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def default_ignored_keys
|
30
|
-
[
|
30
|
+
[
|
31
|
+
model.primary_key,
|
32
|
+
model.inheritance_column,
|
33
|
+
model.locking_column,
|
34
|
+
'created_at',
|
35
|
+
'updated_at'
|
36
|
+
].compact.map(&:to_s)
|
31
37
|
end
|
32
38
|
end
|
33
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-journal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mkiroshdz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -148,7 +148,7 @@ files:
|
|
148
148
|
- ".gitignore"
|
149
149
|
- ".rspec"
|
150
150
|
- ".rubocop.yml"
|
151
|
-
-
|
151
|
+
- CHANGELOG.md
|
152
152
|
- Dockerfile
|
153
153
|
- Gemfile
|
154
154
|
- Gemfile.lock
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at nika.kirosh@gmail.com. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|