save_chain_inspector 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -10
- data/lib/save_chain_inspector/version.rb +1 -1
- data/lib/save_chain_inspector.rb +40 -30
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24d9d01dd7b99d009b463ea942a213bd50bb6c056d580b08192526b1b35dc830
|
4
|
+
data.tar.gz: a0c2e7d89d672935e0942e5da70fa1d81fe6a955b62b6d48e7ecf9bece02523f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8db4e2cef5fd9b5fe56d59ff2188c8b9d5f9675ea1a071e8f63f048f388eee79547aa11c82cff6476eeb1734a4185dea17383623d8aa81502b73083ad2cdc8e6
|
7
|
+
data.tar.gz: 912fa4cb6ad19f39389fc06fdbab418a80f2ba120915b218ce10bd14cca4d9d3f4d85101fcf7c186a9efdb084b3838e664d943b11d0065411ace6a59766f9c6c
|
data/README.md
CHANGED
@@ -26,16 +26,20 @@ end
|
|
26
26
|
|
27
27
|
```
|
28
28
|
Post#save start
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
Post#before_save start
|
30
|
+
Post#before_save end
|
31
|
+
Post#after_create start
|
32
|
+
Post#autosave_associated_records_for_comments start
|
33
|
+
Comment#save start
|
34
|
+
Comment#before_save start
|
35
|
+
Comment#autosave_associated_records_for_post start
|
36
|
+
Comment#autosave_associated_records_for_post end
|
37
|
+
Comment#before_save end
|
38
|
+
Comment#after_create start
|
39
|
+
Comment#after_create end
|
40
|
+
Comment#save end
|
41
|
+
Post#autosave_associated_records_for_comments end
|
42
|
+
Post#after_create end
|
39
43
|
Post#save end
|
40
44
|
```
|
41
45
|
|
data/lib/save_chain_inspector.rb
CHANGED
@@ -4,25 +4,35 @@ require_relative 'save_chain_inspector/version'
|
|
4
4
|
|
5
5
|
class SaveChainInspector # rubocop:disable Metrics/ClassLength, Style/Documentation
|
6
6
|
class << self
|
7
|
-
attr_accessor :
|
8
|
-
|
7
|
+
attr_accessor :indent_count, :enable
|
8
|
+
|
9
|
+
def start(&block)
|
10
|
+
self.indent_count = 0
|
11
|
+
self.enable = true
|
12
|
+
new.call(&block)
|
13
|
+
ensure
|
14
|
+
self.enable = false
|
15
|
+
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
def indent
|
18
|
+
' ' * (indent_count * 2)
|
19
|
+
end
|
20
|
+
|
21
|
+
def increment_indent
|
22
|
+
self.indent_count += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def decrement_indent
|
26
|
+
self.indent_count -= 1 if indent_count.positive?
|
27
|
+
end
|
18
28
|
end
|
19
29
|
|
20
30
|
def initialize
|
21
31
|
ActiveRecord::Base.descendants.each do |klass|
|
22
32
|
next if klass.abstract_class
|
23
|
-
next if
|
33
|
+
next if klass.instance_variable_get(:@save_chain_inspector_initialized)
|
24
34
|
|
25
|
-
|
35
|
+
klass.instance_variable_set(:@save_chain_inspector_initialized, true)
|
26
36
|
add_hooks(klass)
|
27
37
|
end
|
28
38
|
end
|
@@ -33,38 +43,38 @@ class SaveChainInspector # rubocop:disable Metrics/ClassLength, Style/Documentat
|
|
33
43
|
klass.before_save(prepend: true) do |model|
|
34
44
|
next unless SaveChainInspector.enable
|
35
45
|
|
36
|
-
puts "#{
|
37
|
-
SaveChainInspector.
|
46
|
+
puts "#{SaveChainInspector.indent}#{model.class}#before_save start"
|
47
|
+
SaveChainInspector.increment_indent
|
38
48
|
end
|
39
49
|
klass.before_save do |model|
|
40
50
|
next unless SaveChainInspector.enable
|
41
51
|
|
42
|
-
SaveChainInspector.
|
43
|
-
puts "#{
|
52
|
+
SaveChainInspector.decrement_indent
|
53
|
+
puts "#{SaveChainInspector.indent}#{model.class}#before_save end"
|
44
54
|
end
|
45
55
|
klass.set_callback(:create, :after) do |model|
|
46
56
|
next unless SaveChainInspector.enable
|
47
57
|
|
48
|
-
puts "#{
|
49
|
-
SaveChainInspector.
|
58
|
+
puts "#{SaveChainInspector.indent}#{model.class}#after_create start"
|
59
|
+
SaveChainInspector.increment_indent
|
50
60
|
end
|
51
61
|
klass.after_create do |model|
|
52
62
|
next unless SaveChainInspector.enable
|
53
63
|
|
54
|
-
SaveChainInspector.
|
55
|
-
puts "#{
|
64
|
+
SaveChainInspector.decrement_indent
|
65
|
+
puts "#{SaveChainInspector.indent}#{model.class}#after_create end"
|
56
66
|
end
|
57
67
|
klass.set_callback(:update, :after) do |model|
|
58
68
|
next unless SaveChainInspector.enable
|
59
69
|
|
60
|
-
puts "#{
|
61
|
-
SaveChainInspector.
|
70
|
+
puts "#{SaveChainInspector.indent}#{model.class}#after_update start"
|
71
|
+
SaveChainInspector.increment_indent
|
62
72
|
end
|
63
73
|
klass.after_update do |model|
|
64
74
|
next unless SaveChainInspector.enable
|
65
75
|
|
66
|
-
SaveChainInspector.
|
67
|
-
puts "#{
|
76
|
+
SaveChainInspector.decrement_indent
|
77
|
+
puts "#{SaveChainInspector.indent}#{model.class}#after_update end"
|
68
78
|
end
|
69
79
|
end
|
70
80
|
|
@@ -111,19 +121,19 @@ class SaveChainInspector # rubocop:disable Metrics/ClassLength, Style/Documentat
|
|
111
121
|
if trace_point.event == :call
|
112
122
|
if autosave_method?(trace_point) || (save_method?(trace_point) && !duplicate_save_method_call?(trace_point))
|
113
123
|
update_last_call(trace_point)
|
114
|
-
puts "#{
|
115
|
-
self.class.
|
124
|
+
puts "#{self.class.indent}#{trace_point.self.class.name}##{trace_point.method_id} start"
|
125
|
+
self.class.increment_indent
|
116
126
|
end
|
117
127
|
else # :return
|
118
128
|
if save_method?(trace_point) && !duplicate_save_method_return?(trace_point)
|
119
|
-
self.class.
|
129
|
+
self.class.decrement_indent
|
120
130
|
update_last_return(trace_point)
|
121
|
-
puts "#{
|
131
|
+
puts "#{self.class.indent}#{trace_point.self.class.name}##{trace_point.method_id} end"
|
122
132
|
end
|
123
133
|
|
124
134
|
if autosave_method?(trace_point)
|
125
|
-
self.class.
|
126
|
-
puts "#{
|
135
|
+
self.class.decrement_indent
|
136
|
+
puts "#{self.class.indent}#{trace_point.self.class.name}##{trace_point.method_id} end"
|
127
137
|
end
|
128
138
|
end
|
129
139
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: save_chain_inspector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinichi Maeshima
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.5.11
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: A tool to investigate the order in which the saves of related models are
|