markdown_logging_proxy 1.3.0 → 1.3.1

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: 215b4bc73f85cdb7ec9bfa2e3ef3b1efefa55a9d99c34f36007788c798dcbcc0
4
- data.tar.gz: 391123e09db062038d9e4e4ef3aa2a98f15dc07a7727ede676d6a51d7c5cf532
3
+ metadata.gz: e893add5ca96b98f32be5370fb7bfc61e3f80f387392359b4c8e25f9d7e1ca45
4
+ data.tar.gz: 37dd7b894552ba38329279dcb2c8ef23961ca719c23ba1f7a5343e0e1c365c89
5
5
  SHA512:
6
- metadata.gz: 3119ffa9798cf92d8010df9d20738eaf1c7e782de72b40709aba08066270811b31b119ada4ba977e4af67fc5f37da6d455a01afd81ab0a8a62fe944587323c58
7
- data.tar.gz: 6171e82b3677b73c9fa83753a9a21927625427a344b77e07f6285f5090bc1eff156c51504f74310a33bf7fef1bd36bfab4c191423369715b0427d7018b0a475e
6
+ metadata.gz: fd08c3cecf05ef6173ae54c8cd9885e2817c94c141fd3c168c1a04f79f9c267e9fbaebb164cf00ba6670125f4dafd0135a47d39b758b11b043feabf851bf9e8d
7
+ data.tar.gz: '096efff296da1406507b5f2a5531bbf267324a4b53c27ce7ced1b05f85e59b223480e5cb21838b658937a00093cad8e2d961f1c6727a48e85bf3ecf06a9797bb'
data/CHANGELOG.md CHANGED
@@ -37,3 +37,8 @@
37
37
  ## [1.3.0]
38
38
 
39
39
  - Add `inspect_method` configuration option
40
+
41
+ ## [1.3.1]
42
+
43
+ - Object inspection improvements and fixes
44
+ - Implement `inspect_method: :limited` configuration option
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_logging_proxy (1.3.0)
4
+ markdown_logging_proxy (1.3.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -151,14 +151,20 @@ module MarkdownLoggingProxy
151
151
  @ignore.member?(meth)
152
152
  end
153
153
 
154
- def inspect_object(obj, show_id: true)
154
+ def inspect_object(obj, args: false)
155
155
  obj_str =
156
156
  case inspect_method
157
157
  when :inspect then obj.inspect
158
- when :object_id then object_id(obj)
158
+ when :limited then limited_inspect(obj)
159
+ when :id_object
160
+ if args
161
+ "[#{obj.map { |o| id_object(o) }.join(',')}]"
162
+ else
163
+ id_object(obj)
164
+ end
159
165
  when :pretty_inpect
160
166
  [obj.pretty_inspect.chomp].tap do |lines|
161
- lines.prepend "# #{object_id(obj)}" if show_id
167
+ lines.prepend "# #{id_object(obj)}" unless args
162
168
  end.join("\n")
163
169
  else
164
170
  obj.send(inspect_method)
@@ -166,9 +172,31 @@ module MarkdownLoggingProxy
166
172
  ['```ruby', obj_str, '```'].join("\n")
167
173
  end
168
174
 
175
+ # recursive
176
+ def limited_inspect(obj)
177
+ case obj
178
+ when Array
179
+ "[#{obj.map { |o| limited_inspect(o) }.join(',')}]"
180
+ when Hash
181
+ # assumes keys are safe to .inspect
182
+ insides = obj.each { |k, v| "#{k.inspect} => #{limited_inspect(v)}" }
183
+ "{#{insides.join(', ')}}"
184
+ when String, Symbol, Numeric, Class, true, false, nil
185
+ truncated_inspect(obj)
186
+ else
187
+ id_object(obj)
188
+ end
189
+ end
190
+
169
191
  def id_object(object)
170
192
  # #<Object:0xe140>
171
- "`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
193
+ "#<#{object.class}:0x#{object.object_id.to_s(16)}>"
194
+ end
195
+
196
+ def truncated_inspect(obj, limit = 280)
197
+ obj_str = obj.inspect
198
+ obj_str = "#{obj_str.first(limit)}..." if obj_str.length > limit
199
+ obj_str
172
200
  end
173
201
 
174
202
  private
@@ -176,11 +204,11 @@ module MarkdownLoggingProxy
176
204
  def log_call_signature(meth, args, &blk)
177
205
  return if ignore.member?(meth)
178
206
  logger.log :info, 1, <<~MSG.chomp
179
- Calling `#{meth}` on #{id_object(target)}
207
+ Calling `#{meth}` on `#{id_object(target)}`
180
208
 
181
209
  Arguments:
182
210
 
183
- #{inspect_object(args, show_id: false)}
211
+ #{inspect_object(args, args: true)}
184
212
 
185
213
  Block given? #{block_given? ? 'Yes' : 'No'}
186
214
  #{logger.inspect_backtrace}
@@ -194,7 +222,7 @@ module MarkdownLoggingProxy
194
222
  logger.log :info, 3, <<~MSG.chomp
195
223
  Returning proxied response to `#{meth}`
196
224
 
197
- Proxy from `#{meth}` on #{id_object(target)}
225
+ Proxy from `#{meth}` on `#{id_object(target)}`
198
226
 
199
227
  Proxy for:
200
228
 
@@ -214,11 +242,11 @@ module MarkdownLoggingProxy
214
242
  tracer = self
215
243
  proc do |*args|
216
244
  tracer.logger.log :info, 2, <<~MSG.chomp
217
- Yield to block in `#{meth}` on #{tracer.id_object(tracer.target)}
245
+ Yield to block in `#{meth}` on `#{tracer.id_object(tracer.target)}`
218
246
 
219
247
  Arguments:
220
248
 
221
- #{tracer.inspect_object(args, show_id: false)}
249
+ #{tracer.inspect_object(args, args: true)}
222
250
  MSG
223
251
  instance_exec(*args, &blk).tap do |response|
224
252
  tracer.logger.log :info, 3, <<~MSG.chomp
@@ -38,14 +38,20 @@ module MarkdownLoggingProxy
38
38
  @ignore.member?(meth)
39
39
  end
40
40
 
41
- def inspect_object(obj, show_id: true)
41
+ def inspect_object(obj, args: false)
42
42
  obj_str =
43
43
  case inspect_method
44
44
  when :inspect then obj.inspect
45
- when :object_id then object_id(obj)
45
+ when :limited then limited_inspect(obj)
46
+ when :id_object
47
+ if args
48
+ "[#{obj.map { |o| id_object(o) }.join(',')}]"
49
+ else
50
+ id_object(obj)
51
+ end
46
52
  when :pretty_inpect
47
53
  [obj.pretty_inspect.chomp].tap do |lines|
48
- lines.prepend "# #{object_id(obj)}" if show_id
54
+ lines.prepend "# #{id_object(obj)}" unless args
49
55
  end.join("\n")
50
56
  else
51
57
  obj.send(inspect_method)
@@ -53,9 +59,31 @@ module MarkdownLoggingProxy
53
59
  ['```ruby', obj_str, '```'].join("\n")
54
60
  end
55
61
 
62
+ # recursive
63
+ def limited_inspect(obj)
64
+ case obj
65
+ when Array
66
+ "[#{obj.map { |o| limited_inspect(o) }.join(',')}]"
67
+ when Hash
68
+ # assumes keys are safe to .inspect
69
+ insides = obj.each { |k, v| "#{k.inspect} => #{limited_inspect(v)}" }
70
+ "{#{insides.join(', ')}}"
71
+ when String, Symbol, Numeric, Class, true, false, nil
72
+ truncated_inspect(obj)
73
+ else
74
+ id_object(obj)
75
+ end
76
+ end
77
+
56
78
  def id_object(object)
57
79
  # #<Object:0xe140>
58
- "`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
80
+ "#<#{object.class}:0x#{object.object_id.to_s(16)}>"
81
+ end
82
+
83
+ def truncated_inspect(obj, limit = 280)
84
+ obj_str = obj.inspect
85
+ obj_str = "#{obj_str.first(limit)}..." if obj_str.length > limit
86
+ obj_str
59
87
  end
60
88
 
61
89
  private
@@ -63,11 +91,11 @@ module MarkdownLoggingProxy
63
91
  def log_call_signature(meth, args, &blk)
64
92
  return if ignore.member?(meth)
65
93
  logger.log :info, 1, <<~MSG.chomp
66
- Calling `#{meth}` on #{id_object(target)}
94
+ Calling `#{meth}` on `#{id_object(target)}`
67
95
 
68
96
  Arguments:
69
97
 
70
- #{inspect_object(args, show_id: false)}
98
+ #{inspect_object(args, args: true)}
71
99
 
72
100
  Block given? #{block_given? ? 'Yes' : 'No'}
73
101
  #{logger.inspect_backtrace}
@@ -81,7 +109,7 @@ module MarkdownLoggingProxy
81
109
  logger.log :info, 3, <<~MSG.chomp
82
110
  Returning proxied response to `#{meth}`
83
111
 
84
- Proxy from `#{meth}` on #{id_object(target)}
112
+ Proxy from `#{meth}` on `#{id_object(target)}`
85
113
 
86
114
  Proxy for:
87
115
 
@@ -101,11 +129,11 @@ module MarkdownLoggingProxy
101
129
  tracer = self
102
130
  proc do |*args|
103
131
  tracer.logger.log :info, 2, <<~MSG.chomp
104
- Yield to block in `#{meth}` on #{tracer.id_object(tracer.target)}
132
+ Yield to block in `#{meth}` on `#{tracer.id_object(tracer.target)}`
105
133
 
106
134
  Arguments:
107
135
 
108
- #{tracer.inspect_object(args, show_id: false)}
136
+ #{tracer.inspect_object(args, args: true)}
109
137
  MSG
110
138
  instance_exec(*args, &blk).tap do |response|
111
139
  tracer.logger.log :info, 3, <<~MSG.chomp
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "markdown_logging_proxy"
3
- spec.version = "1.3.0"
3
+ spec.version = "1.3.1"
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.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Zulauf