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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb5b157973994040b28e5a9a9db7fae7fba7ce8ca5e5c13a7c5dbc9dc13165d8
4
- data.tar.gz: e88c0bd09a45fce934dedb1af3580e6e0220690e09c865ea142a237a7896834f
3
+ metadata.gz: 24d9d01dd7b99d009b463ea942a213bd50bb6c056d580b08192526b1b35dc830
4
+ data.tar.gz: a0c2e7d89d672935e0942e5da70fa1d81fe6a955b62b6d48e7ecf9bece02523f
5
5
  SHA512:
6
- metadata.gz: aa60bbc1f71bfb213f32992030b8d80d57aac2c8797ef57eb4e421de9d3b219403c7d9944344e620b972afcf3e6ad8af9453a817adef765b4f2f7f26e45477c0
7
- data.tar.gz: eeeb8944be49e80994d87042daa5da60eee32b886e63311f43c95c6185d575268417db34c193db552c9930c36d9d2de0fe76f22c09bbf93be2ed117f2f4a846e
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
- Post#autosave_associated_records_for_comments start
30
- Comment#save start
31
- Comment#before_save start
32
- Comment#autosave_associated_records_for_post start
33
- Comment#autosave_associated_records_for_post end
34
- Comment#before_save end
35
- Comment#after_create start
36
- Comment#after_create end
37
- Comment#save end
38
- Post#autosave_associated_records_for_comments end
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SaveChainInspector
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -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 :indent, :enable
8
- end
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
- self.indent = 0
11
- self.enable = false
12
- def self.start(&block)
13
- self.indent = 0
14
- self.enable = true
15
- new.call(&block)
16
- ensure
17
- self.enable = false
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 @save_chain_inspector_initialized
33
+ next if klass.instance_variable_get(:@save_chain_inspector_initialized)
24
34
 
25
- @save_chain_inspector_initialized = true
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 "#{' ' * (SaveChainInspector.indent * 2)}#{model.class}#before_save start"
37
- SaveChainInspector.indent += 1
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.indent -= 1
43
- puts "#{' ' * (SaveChainInspector.indent * 2)}#{model.class}#before_save end"
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 "#{' ' * (SaveChainInspector.indent * 2)}#{model.class}#after_create start"
49
- SaveChainInspector.indent += 1
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.indent -= 1
55
- puts "#{' ' * (SaveChainInspector.indent * 2)}#{model.class}#after_create end"
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 "#{' ' * (SaveChainInspector.indent * 2)}#{model.class}#after_update start"
61
- SaveChainInspector.indent += 1
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.indent -= 1
67
- puts "#{' ' * (SaveChainInspector.indent * 2)}#{model.class}#after_update end"
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 "#{' ' * (self.class.indent * 2)}#{trace_point.self.class.name}##{trace_point.method_id} start"
115
- self.class.indent += 1
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.indent -= 1
129
+ self.class.decrement_indent
120
130
  update_last_return(trace_point)
121
- puts "#{' ' * (self.class.indent * 2)}#{trace_point.self.class.name}##{trace_point.method_id} end"
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.indent -= 1
126
- puts "#{' ' * (self.class.indent * 2)}#{trace_point.self.class.name}##{trace_point.method_id} end"
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.0
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-07-28 00:00:00.000000000 Z
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.4.20
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