save_chain_inspector 0.1.1 → 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: 98ef7216a3ec9c08d05f6a9127a8f9c5d3c897fc0cf5aace85688e061236765a
4
- data.tar.gz: 98f89513a34d712a2344e4b69c760d8b1042e0498ae80529135a02de0e4b1df5
3
+ metadata.gz: 24d9d01dd7b99d009b463ea942a213bd50bb6c056d580b08192526b1b35dc830
4
+ data.tar.gz: a0c2e7d89d672935e0942e5da70fa1d81fe6a955b62b6d48e7ecf9bece02523f
5
5
  SHA512:
6
- metadata.gz: b15ca7f3cc0353e5cb4cea50770c7038a510fd685d4460322909a76d847550e2713d84bfa662cac8e1b69a050da51547065da6fea9bf9cdac55e24d7f2a43050
7
- data.tar.gz: 58e9b90944321c1ec6e65aec51409de42387198b7c66cfc7573a68f70a991307348612c83e701fbe9e845084541b553d011ca672f06e3e9b52e258b9dd1a32c0
6
+ metadata.gz: 8db4e2cef5fd9b5fe56d59ff2188c8b9d5f9675ea1a071e8f63f048f388eee79547aa11c82cff6476eeb1734a4185dea17383623d8aa81502b73083ad2cdc8e6
7
+ data.tar.gz: 912fa4cb6ad19f39389fc06fdbab418a80f2ba120915b218ce10bd14cca4d9d3f4d85101fcf7c186a9efdb084b3838e664d943b11d0065411ace6a59766f9c6c
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SaveChainInspector
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -4,17 +4,27 @@ 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
@@ -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.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-07-29 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