snapcher 0.2.0 → 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/Gemfile.lock +1 -1
- data/README.md +12 -0
- data/lib/snapcher/junker.rb +9 -4
- data/lib/snapcher/version.rb +1 -1
- data/lib/snapcher.rb +1 -0
- data/sample-app/Gemfile.lock +1 -1
- data/sample-app/app/models/gift.rb +3 -0
- data/sample-app/app/models/user.rb +1 -1
- data/sample-app/db/migrate/20240625084542_create_gifts.rb +11 -0
- data/sample-app/db/schema.rb +19 -1
- metadata +4 -3
- data/logo/snapcher_logo.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e451f8410d9ef2ca33254b255bdde727d2f9a3872f585adc858f60db6aa790d3
|
4
|
+
data.tar.gz: e65e54268eec21fd4319d70db673f92c79bda6236a034fc47d78dadbeb8ce3a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7467703fdd41b839c084d3cb3f0bdcb391c0bdb71bb998624bb15851a63182d25b606345466451854a55473c38b0cd6d9653fd457d027d3152a1b344962de25b
|
7
|
+
data.tar.gz: 0e94835a649439317cc0a0f2ffa0e0dceb8821f462f4707e6492ed9c3994532700dca74843e8327ea85e014dd16add2fc5f542ba1f22ad8aad8b2a46380e68ef
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,10 @@ When a change is made to a specific column, the difference between before and af
|
|
13
13
|
|
14
14
|
To make it easier for analysts, save the table name, column name, and data before and after changes as separate columns.
|
15
15
|
|
16
|
+
The name of this gem comes from one of Hideo Kojima's game works, ["Snatcher"](https://en.wikipedia.org/wiki/Snatcher_(video_game)).
|
17
|
+
|
18
|
+
It was the first of his game works to introduce cinematic direction, and "Snapcher" is also the first of my gem works.
|
19
|
+
|
16
20
|
## Supported
|
17
21
|
|
18
22
|
### Snapcher supports Ruby versions:
|
@@ -76,3 +80,11 @@ snapcher.action # => "update"
|
|
76
80
|
snapcher.before_params # => "Gillian Seed"
|
77
81
|
snapcher.after_params # => "Mika Slayton"
|
78
82
|
```
|
83
|
+
If the "Snatcher" column you want to capture is not user_id, you can specify this.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
class User < ActiveRecord::Base
|
87
|
+
scanning column_name: "name", change_user_column: "id"
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
data/lib/snapcher/junker.rb
CHANGED
@@ -32,7 +32,7 @@ module Snapcher
|
|
32
32
|
run_scanning(action: "create",
|
33
33
|
column_name: snapcher_options[:column_name],
|
34
34
|
after_params: snapcher_attributes[snapcher_options[:column_name]],
|
35
|
-
user_id:
|
35
|
+
user_id: snatch,
|
36
36
|
table_name: self.class.table_name)
|
37
37
|
end
|
38
38
|
|
@@ -42,7 +42,7 @@ module Snapcher
|
|
42
42
|
run_scanning(action: "update",
|
43
43
|
column_name: snapcher_options[:column_name],
|
44
44
|
table_name: self.class.table_name,
|
45
|
-
user_id:
|
45
|
+
user_id: snatch,
|
46
46
|
before_params: snapcher_changes[:before_params],
|
47
47
|
after_params: snapcher_changes[:after_params])
|
48
48
|
end
|
@@ -53,7 +53,7 @@ module Snapcher
|
|
53
53
|
run_scanning(action: "destroy",
|
54
54
|
column_name: snapcher_options[:column_name],
|
55
55
|
table_name: self.class.table_name,
|
56
|
-
user_id:
|
56
|
+
user_id: snatch)
|
57
57
|
end
|
58
58
|
|
59
59
|
# List of attributes that are snapcher.
|
@@ -62,6 +62,10 @@ module Snapcher
|
|
62
62
|
normalize_enum_changes(snapcher_attributes)
|
63
63
|
end
|
64
64
|
|
65
|
+
def snatch
|
66
|
+
snapcher_attributes[snapcher_options[:change_user_column]] || snapcher_attributes["user_id"]
|
67
|
+
end
|
68
|
+
|
65
69
|
def scanning_change_values
|
66
70
|
all_changes = if respond_to?(:changes_to_save)
|
67
71
|
changes_to_save
|
@@ -75,9 +79,10 @@ module Snapcher
|
|
75
79
|
end
|
76
80
|
|
77
81
|
def snapcher_changes
|
82
|
+
snapcher_attributes = filter_encrypted_attrs(attributes)
|
78
83
|
filtered_changes = scanning_change_values
|
79
|
-
|
80
84
|
monitoring_column_name = snapcher_options[:column_name]
|
85
|
+
change_user_column = snapcher_options[:change_user_column]
|
81
86
|
|
82
87
|
return if filtered_changes[monitoring_column_name.to_s].nil?
|
83
88
|
|
data/lib/snapcher/version.rb
CHANGED
data/lib/snapcher.rb
CHANGED
data/sample-app/Gemfile.lock
CHANGED
data/sample-app/db/schema.rb
CHANGED
@@ -10,7 +10,24 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema[7.1].define(version:
|
13
|
+
ActiveRecord::Schema[7.1].define(version: 2024_06_25_084542) do
|
14
|
+
create_table "gifts", force: :cascade do |t|
|
15
|
+
t.integer "from_user_id"
|
16
|
+
t.integer "to_user_id"
|
17
|
+
t.string "name"
|
18
|
+
t.datetime "created_at", null: false
|
19
|
+
t.datetime "updated_at", null: false
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "posts", force: :cascade do |t|
|
23
|
+
t.string "title"
|
24
|
+
t.text "body"
|
25
|
+
t.integer "user_id", null: false
|
26
|
+
t.datetime "created_at", null: false
|
27
|
+
t.datetime "updated_at", null: false
|
28
|
+
t.index ["user_id"], name: "index_posts_on_user_id"
|
29
|
+
end
|
30
|
+
|
14
31
|
create_table "scannings", force: :cascade do |t|
|
15
32
|
t.integer "scannable_id"
|
16
33
|
t.string "scannable_type"
|
@@ -36,4 +53,5 @@ ActiveRecord::Schema[7.1].define(version: 2024_05_09_025320) do
|
|
36
53
|
t.datetime "updated_at", null: false
|
37
54
|
end
|
38
55
|
|
56
|
+
add_foreign_key "posts", "users"
|
39
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snapcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryosk7
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Snapcher is an ORM extension that logs changes to specific columns to your model.
|
@@ -43,7 +43,6 @@ files:
|
|
43
43
|
- lib/snapcher/scanning.rb
|
44
44
|
- lib/snapcher/sweeper.rb
|
45
45
|
- lib/snapcher/version.rb
|
46
|
-
- logo/snapcher_logo.png
|
47
46
|
- sample-app/.dockerignore
|
48
47
|
- sample-app/.gitattributes
|
49
48
|
- sample-app/.gitignore
|
@@ -62,6 +61,7 @@ files:
|
|
62
61
|
- sample-app/app/jobs/application_job.rb
|
63
62
|
- sample-app/app/models/application_record.rb
|
64
63
|
- sample-app/app/models/concerns/.keep
|
64
|
+
- sample-app/app/models/gift.rb
|
65
65
|
- sample-app/app/models/post.rb
|
66
66
|
- sample-app/app/models/user.rb
|
67
67
|
- sample-app/app/views/layouts/application.html.erb
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- sample-app/db/migrate/20231019151334_install_snapcher.rb
|
92
92
|
- sample-app/db/migrate/20240509025320_add_user_id_to_scannings.rb
|
93
93
|
- sample-app/db/migrate/20240509080448_create_posts.rb
|
94
|
+
- sample-app/db/migrate/20240625084542_create_gifts.rb
|
94
95
|
- sample-app/db/schema.rb
|
95
96
|
- sample-app/db/seeds.rb
|
96
97
|
- sample-app/lib/assets/.keep
|
data/logo/snapcher_logo.png
DELETED
Binary file
|