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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 494c49faf14017fbe5f13d5fd7f657a7b2fad2b78ac9264c83497217a70c7977
4
- data.tar.gz: 6bc6340796e5344951ee7dbf02362978a512a5ca9230acb1d68c9e7293a7362d
3
+ metadata.gz: e451f8410d9ef2ca33254b255bdde727d2f9a3872f585adc858f60db6aa790d3
4
+ data.tar.gz: e65e54268eec21fd4319d70db673f92c79bda6236a034fc47d78dadbeb8ce3a3
5
5
  SHA512:
6
- metadata.gz: 91d9af61604cd3a0693c832f32ccf7e92c963e913b9800cebf7a6a4094646edca7b559a61b207a5f10f0f1e2149e2e833e156d1d192ca67df6b32a08cb9fe737
7
- data.tar.gz: 5e734b6997ef32f8f7fda3f2f23a9267ffa3ef01fa5268fe3303b222d9e20036f71925b2463ed526b62dd34a5fe5a89b74e57b000f07aaefa9c91b36ad51bae9
6
+ metadata.gz: 7467703fdd41b839c084d3cb3f0bdcb391c0bdb71bb998624bb15851a63182d25b606345466451854a55473c38b0cd6d9653fd457d027d3152a1b344962de25b
7
+ data.tar.gz: 0e94835a649439317cc0a0f2ffa0e0dceb8821f462f4707e6492ed9c3994532700dca74843e8327ea85e014dd16add2fc5f542ba1f22ad8aad8b2a46380e68ef
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snapcher (0.1.5)
4
+ snapcher (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
+
@@ -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: snapcher_attributes["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: snapcher_attributes["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: snapcher_attributes["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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snapcher
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/snapcher.rb CHANGED
@@ -12,6 +12,7 @@ module Snapcher
12
12
 
13
13
  class << self
14
14
  attr_accessor :column_name, :current_user
15
+ attr_accessor :change_user_column
15
16
  attr_writer :scanning_class
16
17
 
17
18
  def scanning_class
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- snapcher (0.2.0)
4
+ snapcher (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,3 @@
1
+ class Gift < ApplicationRecord
2
+ scanning column_name: "name", change_user_column: "from_user_id"
3
+ end
@@ -1,5 +1,5 @@
1
1
  class User < ApplicationRecord
2
- scanning column_name: "role"
2
+ scanning column_name: "role", change_user_column: "id"
3
3
 
4
4
  enum :role, { normal: 0, admin: 1 }
5
5
  end
@@ -0,0 +1,11 @@
1
+ class CreateGifts < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :gifts do |t|
4
+ t.integer :from_user_id
5
+ t.integer :to_user_id
6
+ t.string :name
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -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: 2024_05_09_025320) do
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.2.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-05-09 00:00:00.000000000 Z
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
Binary file