paper_trail-rails 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +22 -6
- data/lib/paper_trail/rails/console.rb +1 -1
- 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 +20 -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: 6aa5868c6142fc4fe53860a3d2419e4f8f564ecc6f885b35a2c2378b414c39ca
|
4
|
+
data.tar.gz: b6ea9745e16cbb603de44aaae7a8f25fd75c3953d7c8a5bb55467dd6d3434008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eb0038d9fb7de316971d81955f430fc24c43146f176dc491d6641b5346b4102e2d2ed5150cf85cdcea7a9239485052129f519ffefc5df92e5609a3e779ec5e4
|
7
|
+
data.tar.gz: 9202e8d1e38fe06436a59f0ce2051867517297ed9b91f71aba5b640b74e8214ca18e068e1345e070bffeb908bc5f8e94747981f7aacf80e40408efa47c49382e
|
data/Changelog.md
CHANGED
@@ -1,13 +1,29 @@
|
|
1
|
+
## 0.6.0 (2023-06-14)
|
2
|
+
- Include the rails subcommand (`'rails console'`, etc.) in the `command` metadata, not just `'rails'`
|
3
|
+
- When using `rails runner`, include the full Ruby code/file that was run in the `command` metadata.
|
4
|
+
|
5
|
+
## 0.5.2 (2022-04-26)
|
6
|
+
- Fix: Don't update `PaperTrail.request.controller_info[:reason]` if reason is already present and we didn't even ask for a new reason
|
7
|
+
|
8
|
+
## 0.5.1 (2022-04-26)
|
9
|
+
- Update due to upstream paper_trail defining `PaperTrail::Railtie` instead of `PaperTrail::Rails::Engine`
|
10
|
+
|
11
|
+
## 0.5.0 (2022-04-26)
|
12
|
+
- Don't ask for reason if `PaperTrail.request.controller_info[:reason]` is already present.
|
13
|
+
|
14
|
+
For example, if you call a method that programatically sets the reason, then it shouldn't ask you to
|
15
|
+
manually type in a reason.
|
16
|
+
|
1
17
|
## 0.4.0 (2020-04-23)
|
2
18
|
- 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
|
19
|
+
- Add `config.select_user_inspect`
|
20
|
+
- Fix: Remove `.default_order` which may not be defined. Included as config example instead.
|
21
|
+
- Fix: Replace `respond.id` with `respond_to?(:id)`
|
22
|
+
- Fix: Should use `require_user` rather than `require_reason`
|
7
23
|
|
8
24
|
## 0.3.0 (2019-09-16)
|
9
|
-
- Fix: When running db:migrate:redo
|
10
|
-
instead of as "rails db:migrate: MigrationName (up)" as intended.
|
25
|
+
- Fix: When running `db:migrate:redo`, command got recorded as `"rails db:migrate:redo VERSION=2019…"`
|
26
|
+
instead of as `"rails db:migrate: MigrationName (up)"` as intended.
|
11
27
|
- Add `config.source_location_filter`
|
12
28
|
|
13
29
|
## 0.2.2 (2019-07-18)
|
@@ -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'
|
@@ -27,7 +31,7 @@ module PaperTrail
|
|
27
31
|
# Store some metadata about where the change came from
|
28
32
|
def set_default_metadata
|
29
33
|
PaperTrail.update_metadata(
|
30
|
-
command:
|
34
|
+
command: default_command,
|
31
35
|
source_location: caller.find { |line|
|
32
36
|
line.starts_with? ::Rails.root.to_s and
|
33
37
|
config.source_location_filter.(line)
|
@@ -35,6 +39,21 @@ module PaperTrail
|
|
35
39
|
)
|
36
40
|
end
|
37
41
|
|
42
|
+
def default_command
|
43
|
+
program_name = File.basename($PROGRAM_NAME)
|
44
|
+
returning = program_name
|
45
|
+
returning << " #{rails_subcommand}" if program_name == 'rails'
|
46
|
+
returning << " #{ARGV.join(' ')}" if ARGV.any?
|
47
|
+
returning
|
48
|
+
end
|
49
|
+
|
50
|
+
def rails_subcommand
|
51
|
+
regexp = %r{lib/rails/commands/\w+/(\w+)_command\.rb}
|
52
|
+
if (frame = caller.detect { |f| f =~ regexp })
|
53
|
+
frame.match(regexp)[1]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
38
57
|
def select_user(required: false)
|
39
58
|
other_allowed_values = config.select_user_other_allowed_values
|
40
59
|
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.0
|
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
|