action_tracer 0.2.6 → 0.2.7
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/.github/workflows/main.yml +38 -0
- data/.gitignore +2 -1
- data/Gemfile +12 -0
- data/README.md +5 -4
- data/Rakefile +6 -3
- data/action_tracer.gemspec +1 -0
- data/lib/action_tracer/action_tracer.rb +25 -3
- data/lib/action_tracer/filters.rb +9 -3
- data/lib/action_tracer/monkey_patches/abstract_controller/callbacks.rb +1 -0
- data/lib/action_tracer/monkey_patches/active_support/callbacks.rb +12 -55
- data/lib/action_tracer/railtie.rb +0 -24
- data/lib/action_tracer/version.rb +1 -1
- data/log/.keep +0 -0
- metadata +19 -8
- data/.rspec +0 -3
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1bf1d21b80f9a16147c4b61391671280b224b733e01cb06d935e8e5cc33e2429
|
|
4
|
+
data.tar.gz: 37786c2bd84386ace0059bae5bfe08b7d76900c0aac136b807f1b593a60a52b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 71d4924fa5180a4883e5df715e61b638e7d76f4faee62feb4e37ae0d3255eb6ac8b3c5ca75b757900fa22e1e917e813d3b7fd1bb51635f9159f718c5a026d20b
|
|
7
|
+
data.tar.gz: 4b5ed78fbbf89ac1cf7ced8362bc599791bcb49e3a337d55ab4eaed3ce6fa62a982509859533d134371cacbc6cd7330fb1187bc7986fd80fc41e6848966f3350
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches: [master]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
strategy:
|
|
11
|
+
fail-fast: false
|
|
12
|
+
matrix:
|
|
13
|
+
ruby_version: ['3.0', '3.1', '3.2', '3.3', '3.4']
|
|
14
|
+
rails_version: ['7.1', '7.2', '8.0', '8.1']
|
|
15
|
+
exclude:
|
|
16
|
+
- ruby_version: '3.0'
|
|
17
|
+
rails_version: '7.2'
|
|
18
|
+
- ruby_version: '3.0'
|
|
19
|
+
rails_version: '8.0'
|
|
20
|
+
- ruby_version: '3.1'
|
|
21
|
+
rails_version: '8.0'
|
|
22
|
+
- ruby_version: '3.0'
|
|
23
|
+
rails_version: '8.1'
|
|
24
|
+
- ruby_version: '3.1'
|
|
25
|
+
rails_version: '8.1'
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
env:
|
|
28
|
+
RAILS_VERSION: ${{ matrix.rails_version }}
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v6
|
|
31
|
+
- name: Set up Ruby
|
|
32
|
+
uses: ruby/setup-ruby@v1
|
|
33
|
+
with:
|
|
34
|
+
ruby-version: ${{ matrix.ruby_version }}
|
|
35
|
+
bundler-cache: true
|
|
36
|
+
- name: Run the default task
|
|
37
|
+
run: |
|
|
38
|
+
bundle exec rake
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
|
@@ -6,3 +6,15 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
|
6
6
|
|
|
7
7
|
# Specify your gem's dependencies in action_tracer.gemspec
|
|
8
8
|
gemspec
|
|
9
|
+
|
|
10
|
+
rails_version = ENV['RAILS_VERSION']
|
|
11
|
+
if rails_version
|
|
12
|
+
version = "~> #{rails_version}"
|
|
13
|
+
%w[actionpack activesupport railties].each do |gem_name|
|
|
14
|
+
gem gem_name, version
|
|
15
|
+
end
|
|
16
|
+
else
|
|
17
|
+
%w[actionpack activesupport railties].each do |gem_name|
|
|
18
|
+
gem gem_name
|
|
19
|
+
end
|
|
20
|
+
end
|
data/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Log Rails application actions and filters when accepts a request.
|
|
|
7
7
|
Add this line to your application's Gemfile:
|
|
8
8
|
|
|
9
9
|
```ruby
|
|
10
|
-
gem 'action_tracer', group :development, :test
|
|
10
|
+
gem 'action_tracer', group: [:development, :test]
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Notice this gem is for Rails with ApplicationController inherited ActiveController::Base.
|
|
@@ -27,7 +27,7 @@ class AwesomeController < ApplicationController
|
|
|
27
27
|
before_action :set_awesome, only: :show
|
|
28
28
|
around_action :with_readonly
|
|
29
29
|
after_action :store_location
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
def index
|
|
32
32
|
# ...
|
|
33
33
|
end
|
|
@@ -67,7 +67,7 @@ I, [2020-09-27T03:25:43.025547 #1] INFO -- : ["ACTION", :index, "app/controller
|
|
|
67
67
|
I, [2020-09-27T03:25:43.026297 #1] INFO -- : ["APPLIED", :with_readonly, "app/controllers/awesome_controller.rb", 21]
|
|
68
68
|
I, [2020-09-27T03:25:43.027203 #1] INFO -- : ["APPLIED", :store_location, "app/controllers/awesome_controller.rb", 27]
|
|
69
69
|
I, [2020-09-27T03:25:43.030074 #1] INFO -- : ["APPLIED", :verify_same_origin_request, "/usr/local/bundle/gems/actionpack-5.1.7/lib/action_controller/metal/request_forgery_protection.rb", 240]
|
|
70
|
-
I, [2020-09-27T03:25:43.030776 #1] INFO -- :
|
|
70
|
+
I, [2020-09-27T03:25:43.030776 #1] INFO -- :
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
Filters are put in the order in which is executed.
|
|
@@ -81,9 +81,10 @@ Normally log is put in this format:
|
|
|
81
81
|
["APPLIED", :require_login, "app/controllers/awesome_controller.rb", 17]
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
1. State. One of `APPLIED`, `NO_APPLIED` and `ACTION`.
|
|
84
|
+
1. State. One of `APPLIED`, `NO_APPLIED`, `NOT_TRACED` and `ACTION`.
|
|
85
85
|
`APPLIED`: Filter is executed.
|
|
86
86
|
`NO_APPLIED`: Filter is registered but not executed.
|
|
87
|
+
`NOT_TRACED`: Filter is a Proc. Execution status is not traced.
|
|
87
88
|
`ACTION`: Called action.
|
|
88
89
|
2. Method name. When filter is a Proc, just put `:Proc`.
|
|
89
90
|
3. File path. In your application directory, it's omitted path. See Configuration section for details.
|
data/Rakefile
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "bundler/gem_tasks"
|
|
4
|
-
require "
|
|
4
|
+
require "rake/testtask"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << "test"
|
|
8
|
+
t.pattern = "test/**/*_test.rb"
|
|
9
|
+
end
|
|
7
10
|
|
|
8
|
-
task default: :
|
|
11
|
+
task default: :test
|
data/action_tracer.gemspec
CHANGED
|
@@ -5,17 +5,39 @@ module ActionTracer
|
|
|
5
5
|
|
|
6
6
|
class << self
|
|
7
7
|
def log(controller)
|
|
8
|
-
|
|
8
|
+
yield
|
|
9
9
|
ensure
|
|
10
10
|
Filters.build(controller).print
|
|
11
11
|
applied_filters.clear
|
|
12
12
|
ActionTracer.logger.info ""
|
|
13
|
-
|
|
14
|
-
result
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
def applied_filters
|
|
18
16
|
@applied_filters ||= []
|
|
19
17
|
end
|
|
18
|
+
|
|
19
|
+
def wrap_callbacks(controller)
|
|
20
|
+
klass = controller.class
|
|
21
|
+
@wrapped_classes ||= []
|
|
22
|
+
return if @wrapped_classes.include?(klass)
|
|
23
|
+
|
|
24
|
+
filter_method = Rails::VERSION::MAJOR > 6 ? :filter : :raw_filter
|
|
25
|
+
raw_filters = controller.__callbacks[:process_action].__send__(:chain)
|
|
26
|
+
klass.prepend(
|
|
27
|
+
Module.new do
|
|
28
|
+
raw_filters.each do |raw_filter|
|
|
29
|
+
filter = raw_filter.__send__(filter_method)
|
|
30
|
+
next unless filter.is_a?(Symbol)
|
|
31
|
+
|
|
32
|
+
define_method(filter) do |*args, &block|
|
|
33
|
+
ActionTracer.applied_filters << filter
|
|
34
|
+
super(*args, &block)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
@wrapped_classes << klass
|
|
41
|
+
end
|
|
20
42
|
end
|
|
21
43
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module ActionTracer
|
|
4
|
-
APPLIED = { true => "APPLIED", false => "NO_APPLIED", unrecognized: "UNRECOGNIZED", action: "ACTION" }.freeze
|
|
4
|
+
APPLIED = { true => "APPLIED", false => "NO_APPLIED", not_traced: "NOT_TRACED", unrecognized: "UNRECOGNIZED", action: "ACTION" }.freeze
|
|
5
5
|
|
|
6
6
|
class Filter
|
|
7
7
|
PROC = :Proc
|
|
@@ -11,7 +11,7 @@ module ActionTracer
|
|
|
11
11
|
@filter = filter.is_a?(Symbol) ? filter : PROC
|
|
12
12
|
@kind = kind
|
|
13
13
|
@method = method
|
|
14
|
-
@applied = ActionTracer.applied_filters.include?
|
|
14
|
+
@applied = filter.is_a?(Symbol) ? ActionTracer.applied_filters.include?(filter) : :not_traced
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def to_a
|
|
@@ -67,10 +67,16 @@ module ActionTracer
|
|
|
67
67
|
raw_filters = controller.__callbacks[:process_action].__send__(:chain)
|
|
68
68
|
filters = raw_filters.map do |raw_filter|
|
|
69
69
|
filter = raw_filter.__send__(filter_method)
|
|
70
|
+
if filter.is_a?(Symbol)
|
|
71
|
+
method = controller.method(filter)
|
|
72
|
+
method = method.super_method while method.owner.name.nil?
|
|
73
|
+
else
|
|
74
|
+
method = filter
|
|
75
|
+
end
|
|
70
76
|
Filter.new(
|
|
71
77
|
filter,
|
|
72
78
|
kind: raw_filter.kind,
|
|
73
|
-
method:
|
|
79
|
+
method: method,
|
|
74
80
|
)
|
|
75
81
|
end
|
|
76
82
|
new(filters: filters, action: Action.build(controller))
|
|
@@ -4,65 +4,22 @@ module ActionTracer
|
|
|
4
4
|
module MonkeyPatches
|
|
5
5
|
module ActiveSupport
|
|
6
6
|
module Callbacks
|
|
7
|
+
# For Rails::VERSION::MAJOR <= 6
|
|
7
8
|
module CallTemplate
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def inverted_lambda
|
|
19
|
-
super >> proc { |result| ActionTracer.applied_filters << @method_name; result }
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
module ProcCall
|
|
24
|
-
def expand(*)
|
|
25
|
-
super.tap { ActionTracer.applied_filters << @override_target }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def make_lambda
|
|
29
|
-
super >> proc { |result| ActionTracer.applied_filters << @override_target; result }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def inverted_lambda
|
|
33
|
-
super >> proc { |result| ActionTracer.applied_filters << @override_target; result }
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
module InstanceExec
|
|
38
|
-
def expand(*)
|
|
39
|
-
super.tap { ActionTracer.applied_filters << @override_block }
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def make_lambda
|
|
43
|
-
super >> proc { |result| ActionTracer.applied_filters << @override_block; result }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def inverted_lambda
|
|
47
|
-
super >> proc { |result| ActionTracer.applied_filters << @override_block; result }
|
|
9
|
+
def expand(*)
|
|
10
|
+
target, block, method, *arguments = super
|
|
11
|
+
if target.is_a? ActionController::Base
|
|
12
|
+
case method
|
|
13
|
+
when :instance_exec # filter is a proc
|
|
14
|
+
ActionTracer.applied_filters << block
|
|
15
|
+
when String # filter is an object
|
|
16
|
+
ActionTracer.applied_filters << block
|
|
17
|
+
when Symbol # filter is a method
|
|
18
|
+
ActionTracer.applied_filters << method
|
|
48
19
|
end
|
|
49
20
|
end
|
|
50
|
-
else
|
|
51
|
-
def expand(*)
|
|
52
|
-
target, block, method, *arguments = super
|
|
53
|
-
if target.is_a? ActionController::Base
|
|
54
|
-
case method
|
|
55
|
-
when :instance_exec # filter is a proc
|
|
56
|
-
ActionTracer.applied_filters << block
|
|
57
|
-
when String # filter is an object
|
|
58
|
-
ActionTracer.applied_filters << block
|
|
59
|
-
when Symbol # filter is a method
|
|
60
|
-
ActionTracer.applied_filters << method
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
21
|
|
|
64
|
-
|
|
65
|
-
end
|
|
22
|
+
[target, block, method, *arguments]
|
|
66
23
|
end
|
|
67
24
|
end
|
|
68
25
|
end
|
|
@@ -6,30 +6,6 @@ module ActionTracer
|
|
|
6
6
|
class Railtie < ::Rails::Railtie
|
|
7
7
|
initializer "action_tracer" do
|
|
8
8
|
ActiveSupport.on_load(:action_controller) do
|
|
9
|
-
require "action_tracer/monkey_patches/active_support/callbacks"
|
|
10
|
-
if Rails::VERSION::MAJOR > 6
|
|
11
|
-
[
|
|
12
|
-
::ActiveSupport::Callbacks::CallTemplate::MethodCall,
|
|
13
|
-
::ActiveSupport::Callbacks::CallTemplate::ObjectCall,
|
|
14
|
-
].each do |klass|
|
|
15
|
-
klass.prepend ActionTracer::MonkeyPatches::ActiveSupport::Callbacks::CallTemplate::MethodCall
|
|
16
|
-
end
|
|
17
|
-
[
|
|
18
|
-
::ActiveSupport::Callbacks::CallTemplate::InstanceExec0,
|
|
19
|
-
::ActiveSupport::Callbacks::CallTemplate::InstanceExec1,
|
|
20
|
-
::ActiveSupport::Callbacks::CallTemplate::InstanceExec2,
|
|
21
|
-
].each do |klass|
|
|
22
|
-
klass.prepend ActionTracer::MonkeyPatches::ActiveSupport::Callbacks::CallTemplate::InstanceExec
|
|
23
|
-
end
|
|
24
|
-
[
|
|
25
|
-
::ActiveSupport::Callbacks::CallTemplate::ProcCall,
|
|
26
|
-
].each do |klass|
|
|
27
|
-
klass.prepend ActionTracer::MonkeyPatches::ActiveSupport::Callbacks::CallTemplate::ProcCall
|
|
28
|
-
end
|
|
29
|
-
else
|
|
30
|
-
::ActiveSupport::Callbacks::CallTemplate.prepend ActionTracer::MonkeyPatches::ActiveSupport::Callbacks::CallTemplate
|
|
31
|
-
end
|
|
32
|
-
|
|
33
9
|
require "action_tracer/monkey_patches/abstract_controller/callbacks"
|
|
34
10
|
::ActionController::Base.prepend ActionTracer::MonkeyPatches::AbstractController::Callbacks
|
|
35
11
|
|
data/log/.keep
ADDED
|
File without changes
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: action_tracer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- makicamel
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -66,6 +65,20 @@ dependencies:
|
|
|
66
65
|
- - ">="
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rake
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
69
82
|
description: Log Rails application actions and filters when accepts a request
|
|
70
83
|
email:
|
|
71
84
|
- unright@gmail.com
|
|
@@ -73,10 +86,9 @@ executables: []
|
|
|
73
86
|
extensions: []
|
|
74
87
|
extra_rdoc_files: []
|
|
75
88
|
files:
|
|
89
|
+
- ".github/workflows/main.yml"
|
|
76
90
|
- ".gitignore"
|
|
77
|
-
- ".rspec"
|
|
78
91
|
- ".rubocop.yml"
|
|
79
|
-
- ".travis.yml"
|
|
80
92
|
- CHANGELOG.md
|
|
81
93
|
- CODE_OF_CONDUCT.md
|
|
82
94
|
- Gemfile
|
|
@@ -95,11 +107,11 @@ files:
|
|
|
95
107
|
- lib/action_tracer/monkey_patches/active_support/callbacks.rb
|
|
96
108
|
- lib/action_tracer/railtie.rb
|
|
97
109
|
- lib/action_tracer/version.rb
|
|
110
|
+
- log/.keep
|
|
98
111
|
homepage: https://github.com/makicamel/action_tracer
|
|
99
112
|
licenses:
|
|
100
113
|
- MIT
|
|
101
114
|
metadata: {}
|
|
102
|
-
post_install_message:
|
|
103
115
|
rdoc_options: []
|
|
104
116
|
require_paths:
|
|
105
117
|
- lib
|
|
@@ -114,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
114
126
|
- !ruby/object:Gem::Version
|
|
115
127
|
version: '0'
|
|
116
128
|
requirements: []
|
|
117
|
-
rubygems_version: 3.
|
|
118
|
-
signing_key:
|
|
129
|
+
rubygems_version: 3.6.9
|
|
119
130
|
specification_version: 4
|
|
120
131
|
summary: Log Rails application actions and filters when accepts a request
|
|
121
132
|
test_files: []
|
data/.rspec
DELETED