markdown_logging_proxy 1.2.0 → 1.3.0

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: 38a597efa8e2dab27f1fe61005c367d1cfbabd2e1ea5a03e03ec1b29d2baab02
4
- data.tar.gz: f76c90d59eb9c1a911c6eeb2c3e1e2bb8ec881847d9bf8d9cadb0a53ae3378fc
3
+ metadata.gz: 215b4bc73f85cdb7ec9bfa2e3ef3b1efefa55a9d99c34f36007788c798dcbcc0
4
+ data.tar.gz: 391123e09db062038d9e4e4ef3aa2a98f15dc07a7727ede676d6a51d7c5cf532
5
5
  SHA512:
6
- metadata.gz: 108a3acc43c38e7a9fad4773a5d2f2b7b9c55e33b1f6280869316affe6d8b48d342ada65cb170865f672a6f1a77f184a171ccdc6720ebe9c41d5bae8af5ed590
7
- data.tar.gz: 9a696b09265a340d4934c4874cbe0e0977cd6739768d282f145255b128126cdac879e921de452addffa1b94b980dce0d7039d397babd978a179e70b70c09d5aa
6
+ metadata.gz: 3119ffa9798cf92d8010df9d20738eaf1c7e782de72b40709aba08066270811b31b119ada4ba977e4af67fc5f37da6d455a01afd81ab0a8a62fe944587323c58
7
+ data.tar.gz: 6171e82b3677b73c9fa83753a9a21927625427a344b77e07f6285f5090bc1eff156c51504f74310a33bf7fef1bd36bfab4c191423369715b0427d7018b0a475e
data/CHANGELOG.md CHANGED
@@ -33,3 +33,7 @@
33
33
  ## [1.2.0]
34
34
 
35
35
  - Overwrite as many `Object` methods as we can by default
36
+
37
+ ## [1.3.0]
38
+
39
+ - Add `inspect_method` configuration option
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_logging_proxy (1.2.0)
4
+ markdown_logging_proxy (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -4,20 +4,6 @@ require 'pp'
4
4
  require 'time'
5
5
  module MarkdownLoggingProxy
6
6
  class MarkdownLogger
7
- def self.inspect_object(object, show_id = true)
8
- [
9
- '```ruby',
10
- ("# #{id_object(object)}" if show_id),
11
- object.pretty_inspect.chomp,
12
- '```'
13
- ].compact.join("\n")
14
- end
15
-
16
- def self.id_object(object)
17
- # #<Object:0x00007f5a0919e140>
18
- "`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
19
- end
20
-
21
7
  def self.build(location, **options)
22
8
  return location if location.is_a?(MarkdownLogger)
23
9
  new(location, **options)
@@ -94,6 +80,7 @@ module MarkdownLoggingProxy
94
80
  target: nil,
95
81
  location: STDOUT,
96
82
  backtrace: true, # regex/true/false backtrace control
83
+ inspect_method: :pretty_inspect,
97
84
  ignore: [], # methods we shouldn't log/proxy
98
85
  proxy_response: [], # methods we should return a proxy for
99
86
  overwrite: DEFAULT_OVERWRITES
@@ -104,6 +91,7 @@ module MarkdownLoggingProxy
104
91
  target: @target,
105
92
  proxy: self,
106
93
  logger: @logger,
94
+ inspect_method: inspect_method,
107
95
  ignore: ignore,
108
96
  proxy_response: proxy_response,
109
97
  proxy_options: {
@@ -125,18 +113,20 @@ module MarkdownLoggingProxy
125
113
  end
126
114
  module MarkdownLoggingProxy
127
115
  class Tracer
128
- attr_reader :target, :logger, :ignore, :proxy
116
+ attr_reader :target, :logger, :ignore, :proxy, :inspect_method
129
117
 
130
118
  def initialize(
131
119
  target:,
132
120
  proxy:,
133
121
  logger: nil,
122
+ inspect_method: :pretty_inspect,
134
123
  ignore: [],
135
124
  proxy_response: [],
136
125
  proxy_options: {}
137
126
  )
138
127
  @target = target
139
128
  @logger = logger
129
+ @inspect_method = inspect_method
140
130
  @ignore = ignore
141
131
  @proxy_response = proxy_response
142
132
  @proxy_options = proxy_options
@@ -161,16 +151,36 @@ module MarkdownLoggingProxy
161
151
  @ignore.member?(meth)
162
152
  end
163
153
 
154
+ def inspect_object(obj, show_id: true)
155
+ obj_str =
156
+ case inspect_method
157
+ when :inspect then obj.inspect
158
+ when :object_id then object_id(obj)
159
+ when :pretty_inpect
160
+ [obj.pretty_inspect.chomp].tap do |lines|
161
+ lines.prepend "# #{object_id(obj)}" if show_id
162
+ end.join("\n")
163
+ else
164
+ obj.send(inspect_method)
165
+ end
166
+ ['```ruby', obj_str, '```'].join("\n")
167
+ end
168
+
169
+ def id_object(object)
170
+ # #<Object:0xe140>
171
+ "`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
172
+ end
173
+
164
174
  private
165
175
 
166
176
  def log_call_signature(meth, args, &blk)
167
177
  return if ignore.member?(meth)
168
178
  logger.log :info, 1, <<~MSG.chomp
169
- Calling `#{meth}` on #{MarkdownLogger.id_object(target)}
179
+ Calling `#{meth}` on #{id_object(target)}
170
180
 
171
181
  Arguments:
172
182
 
173
- #{MarkdownLogger.inspect_object(args, false)}
183
+ #{inspect_object(args, show_id: false)}
174
184
 
175
185
  Block given? #{block_given? ? 'Yes' : 'No'}
176
186
  #{logger.inspect_backtrace}
@@ -184,15 +194,16 @@ module MarkdownLoggingProxy
184
194
  logger.log :info, 3, <<~MSG.chomp
185
195
  Returning proxied response to `#{meth}`
186
196
 
187
- Proxy from `#{meth}` on #{MarkdownLogger.id_object(target)}
197
+ Proxy from `#{meth}` on #{id_object(target)}
188
198
 
189
199
  Proxy for:
190
200
 
191
- #{MarkdownLogger.inspect_object(response)}
201
+ #{inspect_object(response)}
192
202
  MSG
193
203
  Proxy.new(**@proxy_options.merge(
194
204
  target: response,
195
205
  location: logger,
206
+ inspect_method: inspect_method,
196
207
  proxy_response: @proxy_response,
197
208
  ignore: @ignore,
198
209
  ))
@@ -200,21 +211,20 @@ module MarkdownLoggingProxy
200
211
 
201
212
  def log_and_proxy_block(meth, blk)
202
213
  return if blk.nil?
203
- logger_ref = self.logger
204
- target_ref = self.target
214
+ tracer = self
205
215
  proc do |*args|
206
- logger_ref.log :info, 2, <<~MSG.chomp
207
- Yield to block in `#{meth}` on #{MarkdownLogger.id_object(target_ref)}
216
+ tracer.logger.log :info, 2, <<~MSG.chomp
217
+ Yield to block in `#{meth}` on #{tracer.id_object(tracer.target)}
208
218
 
209
219
  Arguments:
210
220
 
211
- #{MarkdownLogger.inspect_object(args, false)}
221
+ #{tracer.inspect_object(args, show_id: false)}
212
222
  MSG
213
223
  instance_exec(*args, &blk).tap do |response|
214
- logger_ref.log :info, 3, <<~MSG.chomp
224
+ tracer.logger.log :info, 3, <<~MSG.chomp
215
225
  Response from block in `#{meth}`
216
226
 
217
- #{MarkdownLogger.inspect_object(response)}
227
+ #{tracer.inspect_object(response)}
218
228
  MSG
219
229
  end
220
230
  end
@@ -226,7 +236,7 @@ module MarkdownLoggingProxy
226
236
 
227
237
  Type: #{error.class}
228
238
 
229
- #{MarkdownLogger.inspect_object(error)}
239
+ #{inspect_object(error)}
230
240
  MSG
231
241
  raise error
232
242
  end
@@ -236,7 +246,7 @@ module MarkdownLoggingProxy
236
246
  logger.log :info, 2, <<~MSG.chomp
237
247
  `#{meth}` response
238
248
 
239
- #{MarkdownLogger.inspect_object(response)}
249
+ #{inspect_object(response)}
240
250
  MSG
241
251
  end
242
252
  end
@@ -1,19 +1,5 @@
1
1
  module MarkdownLoggingProxy
2
2
  class MarkdownLogger
3
- def self.inspect_object(object, show_id = true)
4
- [
5
- '```ruby',
6
- ("# #{id_object(object)}" if show_id),
7
- object.pretty_inspect.chomp,
8
- '```'
9
- ].compact.join("\n")
10
- end
11
-
12
- def self.id_object(object)
13
- # #<Object:0x00007f5a0919e140>
14
- "`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
15
- end
16
-
17
3
  def self.build(location, **options)
18
4
  return location if location.is_a?(MarkdownLogger)
19
5
  new(location, **options)
@@ -8,6 +8,7 @@ module MarkdownLoggingProxy
8
8
  target: nil,
9
9
  location: STDOUT,
10
10
  backtrace: true, # regex/true/false backtrace control
11
+ inspect_method: :pretty_inspect,
11
12
  ignore: [], # methods we shouldn't log/proxy
12
13
  proxy_response: [], # methods we should return a proxy for
13
14
  overwrite: DEFAULT_OVERWRITES
@@ -18,6 +19,7 @@ module MarkdownLoggingProxy
18
19
  target: @target,
19
20
  proxy: self,
20
21
  logger: @logger,
22
+ inspect_method: inspect_method,
21
23
  ignore: ignore,
22
24
  proxy_response: proxy_response,
23
25
  proxy_options: {
@@ -1,17 +1,19 @@
1
1
  module MarkdownLoggingProxy
2
2
  class Tracer
3
- attr_reader :target, :logger, :ignore, :proxy
3
+ attr_reader :target, :logger, :ignore, :proxy, :inspect_method
4
4
 
5
5
  def initialize(
6
6
  target:,
7
7
  proxy:,
8
8
  logger: nil,
9
+ inspect_method: :pretty_inspect,
9
10
  ignore: [],
10
11
  proxy_response: [],
11
12
  proxy_options: {}
12
13
  )
13
14
  @target = target
14
15
  @logger = logger
16
+ @inspect_method = inspect_method
15
17
  @ignore = ignore
16
18
  @proxy_response = proxy_response
17
19
  @proxy_options = proxy_options
@@ -36,16 +38,36 @@ module MarkdownLoggingProxy
36
38
  @ignore.member?(meth)
37
39
  end
38
40
 
41
+ def inspect_object(obj, show_id: true)
42
+ obj_str =
43
+ case inspect_method
44
+ when :inspect then obj.inspect
45
+ when :object_id then object_id(obj)
46
+ when :pretty_inpect
47
+ [obj.pretty_inspect.chomp].tap do |lines|
48
+ lines.prepend "# #{object_id(obj)}" if show_id
49
+ end.join("\n")
50
+ else
51
+ obj.send(inspect_method)
52
+ end
53
+ ['```ruby', obj_str, '```'].join("\n")
54
+ end
55
+
56
+ def id_object(object)
57
+ # #<Object:0xe140>
58
+ "`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
59
+ end
60
+
39
61
  private
40
62
 
41
63
  def log_call_signature(meth, args, &blk)
42
64
  return if ignore.member?(meth)
43
65
  logger.log :info, 1, <<~MSG.chomp
44
- Calling `#{meth}` on #{MarkdownLogger.id_object(target)}
66
+ Calling `#{meth}` on #{id_object(target)}
45
67
 
46
68
  Arguments:
47
69
 
48
- #{MarkdownLogger.inspect_object(args, false)}
70
+ #{inspect_object(args, show_id: false)}
49
71
 
50
72
  Block given? #{block_given? ? 'Yes' : 'No'}
51
73
  #{logger.inspect_backtrace}
@@ -59,15 +81,16 @@ module MarkdownLoggingProxy
59
81
  logger.log :info, 3, <<~MSG.chomp
60
82
  Returning proxied response to `#{meth}`
61
83
 
62
- Proxy from `#{meth}` on #{MarkdownLogger.id_object(target)}
84
+ Proxy from `#{meth}` on #{id_object(target)}
63
85
 
64
86
  Proxy for:
65
87
 
66
- #{MarkdownLogger.inspect_object(response)}
88
+ #{inspect_object(response)}
67
89
  MSG
68
90
  Proxy.new(**@proxy_options.merge(
69
91
  target: response,
70
92
  location: logger,
93
+ inspect_method: inspect_method,
71
94
  proxy_response: @proxy_response,
72
95
  ignore: @ignore,
73
96
  ))
@@ -75,21 +98,20 @@ module MarkdownLoggingProxy
75
98
 
76
99
  def log_and_proxy_block(meth, blk)
77
100
  return if blk.nil?
78
- logger_ref = self.logger
79
- target_ref = self.target
101
+ tracer = self
80
102
  proc do |*args|
81
- logger_ref.log :info, 2, <<~MSG.chomp
82
- Yield to block in `#{meth}` on #{MarkdownLogger.id_object(target_ref)}
103
+ tracer.logger.log :info, 2, <<~MSG.chomp
104
+ Yield to block in `#{meth}` on #{tracer.id_object(tracer.target)}
83
105
 
84
106
  Arguments:
85
107
 
86
- #{MarkdownLogger.inspect_object(args, false)}
108
+ #{tracer.inspect_object(args, show_id: false)}
87
109
  MSG
88
110
  instance_exec(*args, &blk).tap do |response|
89
- logger_ref.log :info, 3, <<~MSG.chomp
111
+ tracer.logger.log :info, 3, <<~MSG.chomp
90
112
  Response from block in `#{meth}`
91
113
 
92
- #{MarkdownLogger.inspect_object(response)}
114
+ #{tracer.inspect_object(response)}
93
115
  MSG
94
116
  end
95
117
  end
@@ -101,7 +123,7 @@ module MarkdownLoggingProxy
101
123
 
102
124
  Type: #{error.class}
103
125
 
104
- #{MarkdownLogger.inspect_object(error)}
126
+ #{inspect_object(error)}
105
127
  MSG
106
128
  raise error
107
129
  end
@@ -111,7 +133,7 @@ module MarkdownLoggingProxy
111
133
  logger.log :info, 2, <<~MSG.chomp
112
134
  `#{meth}` response
113
135
 
114
- #{MarkdownLogger.inspect_object(response)}
136
+ #{inspect_object(response)}
115
137
  MSG
116
138
  end
117
139
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "markdown_logging_proxy"
3
- spec.version = "1.2.0"
3
+ spec.version = "1.3.0"
4
4
  spec.authors = ["Carl Zulauf"]
5
5
  spec.email = ["carl@linkleaf.com"]
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_logging_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Zulauf