paper_trail-rails 0.5.2 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +28 -6
- data/lib/paper_trail/rails/console.rb +1 -1
- data/lib/paper_trail/rails/paper_trail_extensions.rb +13 -0
- data/lib/paper_trail/rails/runner_command_extensions.rb +46 -0
- data/lib/paper_trail/rails/version.rb +1 -1
- data/lib/paper_trail/rails.rb +22 -1
- data/lib/rails/commands/runner/runner_command.rb +20 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cbd2f0eda94258a20e3a294ed155191773c27af3d91bcbd66c63971084e37e8
|
4
|
+
data.tar.gz: d59ed0df5959182a653556c3583e963ef9df5d2669821f15b4ae06c2deade834
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd93b66499033e9b62bb521bd0870f81fa4a4c4fbe3f4916a5359dbd5fa04279ce5a2ec8396e474062588f70db1170f0e8810293145914dd2f25539451ef298a
|
7
|
+
data.tar.gz: 2b5bd83ee674694032247fec1212dd4ce2a3f49cddaa1ce1380235e4ed3300d3eb0af7ce126942d7beee48c1213e7faf411aff4017565afce8b039206ec1af1d
|
data/Changelog.md
CHANGED
@@ -1,13 +1,35 @@
|
|
1
|
+
## 0.6.1 (2023-06-15)
|
2
|
+
- Add `PaperTrail.metadata`, `PaperTrail.reverse_update_metadata`
|
3
|
+
- Change `set_default_metadata` to only set `command` to `default_command` if it hasn't been set yet. This
|
4
|
+
fixes bug where the command set by `RunnerCommandExtensions` got overwritten when the `whodunnit`
|
5
|
+
callback called `set_default_metadata` again.
|
6
|
+
|
7
|
+
## 0.6.0 (2023-06-14)
|
8
|
+
- Include the rails subcommand (`'rails console'`, etc.) in the `command` metadata, not just `'rails'`
|
9
|
+
- When using `rails runner`, include the full Ruby code/file that was run in the `command` metadata.
|
10
|
+
|
11
|
+
## 0.5.2 (2022-04-26)
|
12
|
+
- Fix: Don't update `PaperTrail.request.controller_info[:reason]` if reason is already present and we didn't even ask for a new reason
|
13
|
+
|
14
|
+
## 0.5.1 (2022-04-26)
|
15
|
+
- Update due to upstream paper_trail defining `PaperTrail::Railtie` instead of `PaperTrail::Rails::Engine`
|
16
|
+
|
17
|
+
## 0.5.0 (2022-04-26)
|
18
|
+
- Don't ask for reason if `PaperTrail.request.controller_info[:reason]` is already present.
|
19
|
+
|
20
|
+
For example, if you call a method that programatically sets the reason, then it shouldn't ask you to
|
21
|
+
manually type in a reason.
|
22
|
+
|
1
23
|
## 0.4.0 (2020-04-23)
|
2
24
|
- Allow user to be selected by index in addition to id
|
3
|
-
- Add config.select_user_inspect
|
4
|
-
- Fix: Remove
|
5
|
-
- Fix: Replace respond.id with respond_to?(:id)
|
6
|
-
- Fix: Should use require_user rather than require_reason
|
25
|
+
- Add `config.select_user_inspect`
|
26
|
+
- Fix: Remove `.default_order` which may not be defined. Included as config example instead.
|
27
|
+
- Fix: Replace `respond.id` with `respond_to?(:id)`
|
28
|
+
- Fix: Should use `require_user` rather than `require_reason`
|
7
29
|
|
8
30
|
## 0.3.0 (2019-09-16)
|
9
|
-
- Fix: When running db:migrate:redo
|
10
|
-
instead of as "rails db:migrate: MigrationName (up)" as intended.
|
31
|
+
- Fix: When running `db:migrate:redo`, command got recorded as `"rails db:migrate:redo VERSION=2019…"`
|
32
|
+
instead of as `"rails db:migrate: MigrationName (up)"` as intended.
|
11
33
|
- Add `config.source_location_filter`
|
12
34
|
|
13
35
|
## 0.2.2 (2019-07-18)
|
@@ -1,5 +1,11 @@
|
|
1
1
|
PaperTrail.class_eval do
|
2
2
|
|
3
|
+
unless methods.include?(:metadata)
|
4
|
+
def self.metadata
|
5
|
+
PaperTrail.request.controller_info
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
unless methods.include?(:with_metadata)
|
4
10
|
# Adds additional metadata to versions created within the given block. This will be merged with
|
5
11
|
# (and may override) any metadata already set by your controller's info_for_paper_trail.
|
@@ -27,4 +33,11 @@ PaperTrail.class_eval do
|
|
27
33
|
PaperTrail.request.controller_info = merged_metadata
|
28
34
|
end
|
29
35
|
end
|
36
|
+
|
37
|
+
unless methods.include?(:reverse_update_metadata)
|
38
|
+
def self.reverse_update_metadata(metadata)
|
39
|
+
merged_metadata = (::PaperTrail.request.controller_info || {}).reverse_merge(metadata)
|
40
|
+
PaperTrail.request.controller_info = merged_metadata
|
41
|
+
end
|
42
|
+
end
|
30
43
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# This needs to be required from lib/rails/commands/runner/runner_command.rb. Otherwise the original
|
2
|
+
# perform method gets called before we've even had a chance to modify it.
|
3
|
+
#
|
4
|
+
# To manually test this, run this from a Rails app that has this gem included:
|
5
|
+
# rails runner 'pp PaperTrail.request.controller_info'
|
6
|
+
|
7
|
+
require_relative 'railtie'
|
8
|
+
|
9
|
+
module PaperTrail
|
10
|
+
module Rails
|
11
|
+
module RunnerCommandExtensions
|
12
|
+
def perform(code_or_file = nil, *command_argv)
|
13
|
+
PaperTrail.request.whodunnit = nil
|
14
|
+
PaperTrail::Rails.set_default_metadata
|
15
|
+
PaperTrail.update_metadata(
|
16
|
+
command: "rails runner: #{code_or_file} #{command_argv.join(' ')}"
|
17
|
+
)
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
# Rails::Command::Base#create_command creates this alias too, and runner is what actually gets
|
22
|
+
# called so we have to override the alias too.
|
23
|
+
alias runner perform
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module Rails
|
29
|
+
module Command
|
30
|
+
( RunnerCommand)
|
31
|
+
class RunnerCommand
|
32
|
+
prepend ::PaperTrail::Rails::RunnerCommandExtensions
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module PaperTrail
|
38
|
+
module Rails
|
39
|
+
class Railtie
|
40
|
+
runner do |application|
|
41
|
+
# Rails provides this callback that is invoked by RunnerCommand#peform before running the
|
42
|
+
# provided code. But it doesn't pass in the args from perform.
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/paper_trail/rails.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'rails'
|
2
|
+
# When rails/commands/runner/runner_command.rb is invoked, it won't have already loaded
|
3
|
+
# active_record, so we need to load it to avoid getting uninitialized constant ActiveRecord.
|
4
|
+
require 'active_record'
|
1
5
|
require 'paper_trail'
|
2
6
|
|
3
7
|
require_relative 'rails/version'
|
@@ -26,8 +30,10 @@ module PaperTrail
|
|
26
30
|
|
27
31
|
# Store some metadata about where the change came from
|
28
32
|
def set_default_metadata
|
33
|
+
PaperTrail.reverse_update_metadata(
|
34
|
+
command: default_command,
|
35
|
+
)
|
29
36
|
PaperTrail.update_metadata(
|
30
|
-
command: "#{File.basename($PROGRAM_NAME)} #{ARGV.join ' '}",
|
31
37
|
source_location: caller.find { |line|
|
32
38
|
line.starts_with? ::Rails.root.to_s and
|
33
39
|
config.source_location_filter.(line)
|
@@ -35,6 +41,21 @@ module PaperTrail
|
|
35
41
|
)
|
36
42
|
end
|
37
43
|
|
44
|
+
def default_command
|
45
|
+
program_name = File.basename($PROGRAM_NAME)
|
46
|
+
returning = program_name
|
47
|
+
returning << " #{rails_subcommand}" if program_name == 'rails'
|
48
|
+
returning << " #{ARGV.join(' ')}" if ARGV.any?
|
49
|
+
returning
|
50
|
+
end
|
51
|
+
|
52
|
+
def rails_subcommand
|
53
|
+
regexp = %r{lib/rails/commands/\w+/(\w+)_command\.rb}
|
54
|
+
if (frame = caller.detect { |f| f =~ regexp })
|
55
|
+
frame.match(regexp)[1]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
38
59
|
def select_user(required: false)
|
39
60
|
other_allowed_values = config.select_user_other_allowed_values
|
40
61
|
other_values_prompt = " (or #{other_allowed_values.join(' or ')})" if other_allowed_values.present?
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file must be at path lib/rails/commands/runner/runner_command.rb so it overrides the file
|
2
|
+
# with the same name in the railties gem. This is the only way to modify the class (prepend a
|
3
|
+
# module) before perform is called on it.
|
4
|
+
|
5
|
+
# pp $LOAD_PATH.index($LOAD_PATH.grep(/railties/).first)
|
6
|
+
# pp $LOAD_PATH.index($LOAD_PATH.grep(/paper_trail-rails/).first)
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'paper_trail/rails'
|
10
|
+
rescue
|
11
|
+
puts $!
|
12
|
+
puts $!.backtrace
|
13
|
+
raise
|
14
|
+
end
|
15
|
+
|
16
|
+
railties_lib = Gem.loaded_specs['railties'].full_require_paths[0]
|
17
|
+
|
18
|
+
require railties_lib + '/rails/commands/runner/runner_command'
|
19
|
+
|
20
|
+
require_relative '../../../paper_trail/rails/runner_command_extensions'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper_trail-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Rick
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paper_trail
|
@@ -105,7 +105,9 @@ files:
|
|
105
105
|
- lib/paper_trail/rails/migration_extensions.rb
|
106
106
|
- lib/paper_trail/rails/paper_trail_extensions.rb
|
107
107
|
- lib/paper_trail/rails/railtie.rb
|
108
|
+
- lib/paper_trail/rails/runner_command_extensions.rb
|
108
109
|
- lib/paper_trail/rails/version.rb
|
110
|
+
- lib/rails/commands/runner/runner_command.rb
|
109
111
|
- paper_trail-rails.gemspec
|
110
112
|
homepage: https://github.com/TylerRick/paper_trail-rails
|
111
113
|
licenses: []
|
@@ -128,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
130
|
- !ruby/object:Gem::Version
|
129
131
|
version: '0'
|
130
132
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.1.6
|
132
134
|
signing_key:
|
133
135
|
specification_version: 4
|
134
136
|
summary: Integrate with rails console and migrations. In rails console, ask who is
|