action_tracer 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -3
- data/CHANGELOG.md +12 -0
- data/action_tracer.gemspec +2 -4
- data/lib/action_tracer/action_tracer.rb +1 -0
- data/lib/action_tracer/filters.rb +37 -8
- data/lib/action_tracer/monkey_patches/active_support/callbacks.rb +55 -11
- data/lib/action_tracer/railtie.rb +23 -1
- data/lib/action_tracer/version.rb +1 -1
- metadata +8 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 421d6789ec680cc762a0844c9182d4dd8b03a5c6371c1a1852cb1fd0e2c0746a
|
4
|
+
data.tar.gz: b13b98ed44e0cb98df31709135170e6764eb11df43ba528d696cfa253835cec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a97e4728b5ca7f02f7ee5c2bb384edeba87bf5eaac370bdf2dbfdc6833ccc7607595618234df5ac7c7e76c1701fcb18e90ffe4ff886528c75ca0a279432b8562
|
7
|
+
data.tar.gz: 1c81fe333dd9815b5dbcd93689d5443e17e39e2bdf4876639e432e66282b5f1f64d993f2f84d9232e065f862ef13c651aacfc58e4fc48b3ad9a19ed07191f0ce
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 0.2.3
|
2
|
+
|
3
|
+
* Deal with Rails7.x.
|
4
|
+
|
5
|
+
## 0.2.2
|
6
|
+
|
7
|
+
* Log filters even when controllers raise error.
|
8
|
+
|
9
|
+
## 0.2.1
|
10
|
+
|
11
|
+
* Fix not to raise error when controllers does not have action definitions.
|
12
|
+
|
1
13
|
## 0.2.0
|
2
14
|
|
3
15
|
* Stop using TracePoint and just override ActiveSupport::Callbacks::CallTemplate
|
data/action_tracer.gemspec
CHANGED
@@ -23,8 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_dependency "activesupport"
|
25
25
|
spec.add_dependency "actionpack"
|
26
|
-
|
27
|
-
spec.add_development_dependency "
|
28
|
-
spec.add_development_dependency "rake"
|
29
|
-
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "byebug"
|
27
|
+
spec.add_development_dependency "minitest"
|
30
28
|
end
|
@@ -22,6 +22,27 @@ module ActionTracer
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
class Action
|
26
|
+
def initialize(name:, method:)
|
27
|
+
@name = name
|
28
|
+
@method = method
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.build(controller)
|
32
|
+
method = controller.respond_to?(controller.action_name) ? controller.method(controller.action_name) : nil_method
|
33
|
+
new(name: controller.action_name, method: method)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_a
|
37
|
+
[APPLIED[:action], @name, *@method.source_location]
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.nil_method
|
41
|
+
method(:p)
|
42
|
+
end
|
43
|
+
private_class_method :nil_method
|
44
|
+
end
|
45
|
+
|
25
46
|
class Filters
|
26
47
|
def initialize(before = [], after = [], around = [], action:)
|
27
48
|
@before = before
|
@@ -30,20 +51,28 @@ module ActionTracer
|
|
30
51
|
@action = action
|
31
52
|
end
|
32
53
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
54
|
+
class << self
|
55
|
+
def build(controller)
|
56
|
+
filters = { before: [], after: [], around: [] }
|
57
|
+
raw_filters = controller.__callbacks[:process_action].send(:chain).group_by(&:kind)
|
58
|
+
raw_filters.each do |kind, filter|
|
59
|
+
filters[kind] = filter.map { |f| f.__send__(filter_method) }.map do |f|
|
60
|
+
Filter.new(f, method: f.is_a?(Symbol) ? controller.method(f) : f)
|
61
|
+
end
|
39
62
|
end
|
63
|
+
new(filters[:before], filters[:after], filters[:around], action: Action.build(controller))
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def filter_method
|
69
|
+
@filter_method ||= Rails::VERSION::MAJOR > 6 ? :filter : :raw_filter
|
40
70
|
end
|
41
|
-
new(filters[:before], filters[:after], filters[:around], action: controller.method(controller.action_name))
|
42
71
|
end
|
43
72
|
|
44
73
|
def print
|
45
74
|
invoked_before.map(&:to_a).each { |filter| ActionTracer.logger.info filter }
|
46
|
-
ActionTracer.logger.info
|
75
|
+
ActionTracer.logger.info @action.to_a
|
47
76
|
invoked_after.map(&:to_a).reverse_each { |filter| ActionTracer.logger.info filter }
|
48
77
|
end
|
49
78
|
|
@@ -5,20 +5,64 @@ module ActionTracer
|
|
5
5
|
module ActiveSupport
|
6
6
|
module Callbacks
|
7
7
|
module CallTemplate
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
ActionTracer.applied_filters <<
|
16
|
-
|
17
|
-
|
8
|
+
if Rails::VERSION::MAJOR > 6
|
9
|
+
module MethodCall
|
10
|
+
def expand(*)
|
11
|
+
super.tap { ActionTracer.applied_filters << @method_name }
|
12
|
+
end
|
13
|
+
|
14
|
+
def make_lambda
|
15
|
+
super >> proc { ActionTracer.applied_filters << @method_name }
|
16
|
+
end
|
17
|
+
|
18
|
+
def inverted_lambda
|
19
|
+
super >> proc { ActionTracer.applied_filters << @method_name }
|
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 { ActionTracer.applied_filters << @override_target }
|
30
|
+
end
|
31
|
+
|
32
|
+
def inverted_lambda
|
33
|
+
super >> proc { ActionTracer.applied_filters << @override_target }
|
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 { ActionTracer.applied_filters << @override_block }
|
44
|
+
end
|
45
|
+
|
46
|
+
def inverted_lambda
|
47
|
+
super >> proc { ActionTracer.applied_filters << @override_block }
|
18
48
|
end
|
19
49
|
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
|
20
63
|
|
21
|
-
|
64
|
+
[target, block, method, *arguments]
|
65
|
+
end
|
22
66
|
end
|
23
67
|
end
|
24
68
|
end
|
@@ -23,7 +23,29 @@ module ActionTracer
|
|
23
23
|
initializer "action_tracer" do
|
24
24
|
ActiveSupport.on_load(:action_controller) do
|
25
25
|
require "action_tracer/monkey_patches/active_support/callbacks"
|
26
|
-
::
|
26
|
+
if Rails::VERSION::MAJOR > 6
|
27
|
+
[
|
28
|
+
::ActiveSupport::Callbacks::CallTemplate::MethodCall,
|
29
|
+
::ActiveSupport::Callbacks::CallTemplate::ObjectCall,
|
30
|
+
].each do |klass|
|
31
|
+
klass.prepend ActionTracer::MonkeyPatches::ActiveSupport::Callbacks::CallTemplate::MethodCall
|
32
|
+
end
|
33
|
+
[
|
34
|
+
::ActiveSupport::Callbacks::CallTemplate::InstanceExec0,
|
35
|
+
::ActiveSupport::Callbacks::CallTemplate::InstanceExec1,
|
36
|
+
::ActiveSupport::Callbacks::CallTemplate::InstanceExec2,
|
37
|
+
].each do |klass|
|
38
|
+
klass.prepend ActionTracer::MonkeyPatches::ActiveSupport::Callbacks::CallTemplate::InstanceExec
|
39
|
+
end
|
40
|
+
[
|
41
|
+
::ActiveSupport::Callbacks::CallTemplate::ProcCall,
|
42
|
+
].each do |klass|
|
43
|
+
klass.prepend ActionTracer::MonkeyPatches::ActiveSupport::Callbacks::CallTemplate::ProcCall
|
44
|
+
end
|
45
|
+
else
|
46
|
+
::ActiveSupport::Callbacks::CallTemplate.prepend ActionTracer::MonkeyPatches::ActiveSupport::Callbacks::CallTemplate
|
47
|
+
end
|
48
|
+
|
27
49
|
require "action_tracer/monkey_patches/abstract_controller/callbacks"
|
28
50
|
::ActionController::Base.prepend ActionTracer::MonkeyPatches::AbstractController::Callbacks
|
29
51
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- makicamel
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: byebug
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,21 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
56
|
+
name: minitest
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - ">="
|
@@ -113,7 +99,7 @@ homepage: https://github.com/makicamel/action_tracer
|
|
113
99
|
licenses:
|
114
100
|
- MIT
|
115
101
|
metadata: {}
|
116
|
-
post_install_message:
|
102
|
+
post_install_message:
|
117
103
|
rdoc_options: []
|
118
104
|
require_paths:
|
119
105
|
- lib
|
@@ -128,8 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
114
|
- !ruby/object:Gem::Version
|
129
115
|
version: '0'
|
130
116
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
-
signing_key:
|
117
|
+
rubygems_version: 3.2.32
|
118
|
+
signing_key:
|
133
119
|
specification_version: 4
|
134
120
|
summary: Log Rails application actions and filters when accepts a request
|
135
121
|
test_files: []
|