im-lost 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 796abdca36d4d079d74289f0634dc097d346accafc3a57bdc67134bb92e6b6e7
4
- data.tar.gz: a996b51a85a883f39becc17271ec0e079a64b51f3e5a187deffc1a0b18b6cd66
3
+ metadata.gz: 997bc0a130f9ac4aad8b517db8b2e1de8ff8d8720c88b6866105e8948e3ee563
4
+ data.tar.gz: 806757992aa14e484919b319c56f3fa694c4c52973b6b32cf925234ea145359c
5
5
  SHA512:
6
- metadata.gz: d69fccba333bb177eae38483db1a4edfda2b3b2ec3ca5e7efe59701bfaa9ab0cda1ddd0d01339e8f3124330ccad73bce148de8054914e55af8e5880db650242d
7
- data.tar.gz: 51b9f2f387f0e93309ce2fd7677627d0b1eb2b3764437a216441f1947e710d6646d519c6e0e1358a93c78709553fd385e71151dafc62f39a07f41b82ae5f056b
6
+ metadata.gz: 14ff2167f66b94d8ffc165dd973a0ca848c7f32818cfe521e2cc82e1a2c0a285e909ceadf6fbeee3c18947d3163264c0faa0d830522bbd81c7ae5fa5a55fc816
7
+ data.tar.gz: c06a25f0310464f1a9ce19ba137a3f6fc5cf644c6c0ac7d9ef421077f3dbb07658014503b411492caa6477cafbc57296ae6eab990aab837db4d009ed2ac4e02f
data/README.md CHANGED
@@ -6,7 +6,7 @@ ImLost helps you by analyzing function calls of objects, informing you about exc
6
6
 
7
7
  - Gem: [rubygems.org](https://rubygems.org/gems/im-lost)
8
8
  - Source: [codeberg.org](https://codeberg.org/mblumtritt/im-lost)
9
- - Help: [rubydoc.info](https://rubydoc.info/gems/im-lost)
9
+ - Help: [rubydoc.info](https://rubydoc.info/gems/im-lost/ImLost)
10
10
 
11
11
  ## Description
12
12
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module ImLost
4
4
  # The version number of the gem.
5
- VERSION = '1.2.3'
5
+ VERSION = '1.2.4'
6
6
  end
data/lib/im-lost.rb CHANGED
@@ -46,7 +46,7 @@ module ImLost
46
46
  # ImLost.output = original
47
47
  # end
48
48
  #
49
- # @return [#puts] the output device
49
+ # @return [#<<] the output device
50
50
  #
51
51
  attr_reader :output
52
52
 
@@ -61,8 +61,8 @@ module ImLost
61
61
  end
62
62
 
63
63
  #
64
- # @return [TimerStore] the timer store used to estimate the runtime of
65
- # your code
64
+ # @return [TimerStore]
65
+ # the timer store used to estimate the runtime of your code
66
66
  #
67
67
  attr_reader :timer
68
68
 
@@ -101,8 +101,9 @@ module ImLost
101
101
  # # x RuntimeError: something went wrong!
102
102
  # # /examples/test.rb:4
103
103
  #
104
- # @param with_locations [Boolean] whether the locations should be included
105
- # into the exception trace information
104
+ # @param with_locations [Boolean]
105
+ # whether the locations should be included into the exception trace
106
+ # information
106
107
  # @yieldreturn [Object] return result
107
108
  #
108
109
  def trace_exceptions(with_locations: true)
@@ -235,8 +236,8 @@ module ImLost
235
236
  #
236
237
  # @see trace
237
238
  #
238
- # @param args [[]Object]] one or more objects which should not longer be
239
- # traced
239
+ # @param args [[]Object]]
240
+ # one or more objects which should not longer be traced
240
241
  # @return [Array<Object>] the object(s) which are not longer be traced
241
242
  # @return [nil] when none of the objects was traced before
242
243
  #
@@ -319,17 +320,38 @@ module ImLost
319
320
  @output << out
320
321
  end
321
322
 
323
+ #
324
+ # Measure runtime of given block.
325
+ #
326
+ # @param title [#to_s] optional title to display
327
+ # @return [Object] the block's result
328
+ #
329
+ def time(title = nil, &block)
330
+ title &&= "#{title} "
331
+ if @caller_locations
332
+ loc = Kernel.caller_locations(1, 1)[0]
333
+ suffix = " #{loc.path}:#{loc.lineno}\n"
334
+ end
335
+ unless block_given?
336
+ @output << "t #{title}#{TimerStore.now}\n#{suffix}"
337
+ return
338
+ end
339
+ t = TimerStore.now
340
+ begin
341
+ yield
342
+ ensure
343
+ t = (TimerStore.now - t).round(4)
344
+ @output << "R #{title}#{t} sec.\n#{suffix} #{block.inspect}\n"
345
+ end
346
+ end
347
+
322
348
  private
323
349
 
324
350
  def _can_trace?(arg)
325
351
  (id = arg.__id__) != __id__ && id != @output.__id__
326
352
  end
327
353
 
328
- def _trace(arg)
329
- @trace[arg] = arg if _can_trace?(arg)
330
- arg
331
- end
332
-
354
+ def _trace(arg) = _can_trace?(arg) ? @trace[arg] = arg : arg
333
355
  def _trace_all(args) = args.each { @trace[_1] = _1 if _can_trace?(_1) }
334
356
 
335
357
  def _trace_b(arg)
@@ -375,8 +397,8 @@ module ImLost
375
397
  storage = fiber.storage || {}
376
398
  out.vars('fiber storage', storage.keys) { storage[_1] }
377
399
  else
378
- out << ' !!! given Fiber is not the current Fiber' <<
379
- " #{fiber.inspect}"
400
+ out << ' !!! given Fiber is not the current Fiber'
401
+ out << " #{fiber.inspect}"
380
402
  end
381
403
  fiber
382
404
  end
@@ -653,10 +675,10 @@ module ImLost
653
675
  @output << out.to_s
654
676
  end
655
677
 
656
- @timer = TimerStore.new { |title, location, time| @output << <<~TIMER_MSG }
678
+ @timer = TimerStore.new { |title, location, time| @output << <<~MSG }
657
679
  T #{title}: #{time ? "#{time} sec." : 'created'}
658
680
  #{location.path}:#{location.lineno}
659
- TIMER_MSG
681
+ MSG
660
682
  TimerStore.private_class_method(:new)
661
683
 
662
684
  untrace_all!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: im-lost
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  requirements: []
57
- rubygems_version: 3.7.1
57
+ rubygems_version: 4.0.0
58
58
  specification_version: 4
59
59
  summary: Your debugging helper.
60
60
  test_files: []