time_up 0.0.1 → 0.0.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: 2814efda7871308dcafe0196407a3bbea424770069d9b998c8728f974a641413
4
- data.tar.gz: 791e65a388e0d62ece0166a747a20cd41f37259d6283e197ff020a05b6eb3e70
3
+ metadata.gz: 3e94465307a2737c930d8dbd195c92fe315850abf8c7be4b1c6f88f1eec2d1bd
4
+ data.tar.gz: 82cac53d1b5c18acdeb7312da3cc929bed1590e707d8ac8edeb0480fff13af29
5
5
  SHA512:
6
- metadata.gz: a697b5da2199813b882d8a1b3994670dde64c8ce5adb95b321a8bef3c8892cda9110e778c505e0fd4c327f1956f474be07db9f5fc008926093af9c60c4a8accf
7
- data.tar.gz: 1b7089abf119e10a4cff97f880d9a05536a960b112ba59a57f6c6d8642771e566b697db88f6d7c7e2fdca73ff0549803864314de7601d0643e0c018cfbc3731e
6
+ metadata.gz: b0a1395d51df9233140f9f7b7dd49d6cdc3bc1c50eea76425da7300a6b165230c17452ecaf7b1721c50a9b87f788775913b93ada281906ab681a19376976a34c
7
+ data.tar.gz: 12856340affc8a8a298986c8b56c01198256346c5cd0caf8f7fac2726ea742d43fc05e113c7f93960c34cae08318b5c5ac912b5b5adb716e03748bef56818b1a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.2
2
+
3
+ - Switch from a module method to Thread.current variable
4
+
1
5
  # 0.0.1
2
6
 
3
7
  - Make the gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- time_up (0.0.1)
4
+ time_up (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -6,10 +6,10 @@ but don't necessarily want to reach for
6
6
  Try `time_up`!
7
7
 
8
8
  This gem is especially useful for long-running processes (like test suites) that
9
- have several time-intensive operations that are repeated over time and that you
10
- want to measure and aggregate. (For example, to see how much time your
11
- test suite spends creating factories, truncating the database, or invoking a
12
- critical code path.)
9
+ have several time-intensive operations that are repeated over the life of the
10
+ process and that you want to measure in aggregate. (For example, to see how
11
+ much time your test suite spends creating factories, truncating the database, or
12
+ invoking a critical code path.)
13
13
 
14
14
  ## Install
15
15
 
data/lib/time_up.rb CHANGED
@@ -3,10 +3,11 @@ require_relative "time_up/version"
3
3
  module TimeUp
4
4
  class Error < StandardError; end
5
5
 
6
- @timers = {}
6
+ Thread.current[:time_up_timers] = {}
7
+
7
8
  def self.start(name, &blk)
8
9
  raise Error.new("Timer name must be a String or Symbol") unless name.is_a?(Symbol) || name.is_a?(String)
9
- timer = @timers[name] ||= Timer.new(name)
10
+ timer = __timers[name] ||= Timer.new(name)
10
11
  timer.start
11
12
  if blk
12
13
  blk.call
@@ -17,42 +18,42 @@ module TimeUp
17
18
 
18
19
  # Delegate methods
19
20
  def self.timer(name)
20
- @timers[name]
21
+ __timers[name]
21
22
  end
22
23
 
23
24
  def self.stop(name)
24
25
  __ensure_timer(name)
25
- @timers[name].stop
26
+ __timers[name].stop
26
27
  end
27
28
 
28
29
  def self.elapsed(name)
29
30
  __ensure_timer(name)
30
- @timers[name].elapsed
31
+ __timers[name].elapsed
31
32
  end
32
33
 
33
34
  def self.reset(name)
34
35
  __ensure_timer(name)
35
- @timers[name].reset
36
+ __timers[name].reset
36
37
  end
37
38
 
38
39
  # Interrogative methods
39
40
  def self.total_elapsed
40
- @timers.values.sum(&:elapsed)
41
+ __timers.values.sum(&:elapsed)
41
42
  end
42
43
 
43
44
  def self.all_elapsed
44
- @timers.values.map { |timer|
45
+ __timers.values.map { |timer|
45
46
  [timer.name, timer.elapsed]
46
47
  }.to_h
47
48
  end
48
49
 
49
50
  def self.active_timers
50
- @timers.values.select(&:active?)
51
+ __timers.values.select(&:active?)
51
52
  end
52
53
 
53
54
  def self.print_summary(io = $stdout)
54
- longest_name_length = @timers.values.map { |t| t.name.inspect.size }.max
55
- summaries = @timers.values.map { |timer|
55
+ longest_name_length = __timers.values.map { |t| t.name.inspect.size }.max
56
+ summaries = __timers.values.map { |timer|
56
57
  name = "#{timer.name.inspect}#{"*" if timer.active?}".ljust(longest_name_length + 1)
57
58
  "#{name}\t#{"%.5f" % timer.elapsed}s"
58
59
  }
@@ -62,27 +63,31 @@ module TimeUp
62
63
  ========================
63
64
  #{summaries.join("\n")}
64
65
 
65
- #{"* Denotes that the timer is still active\n" if @timers.values.any?(&:active?)}
66
+ #{"* Denotes that the timer is still active\n" if __timers.values.any?(&:active?)}
66
67
  SUMMARY
67
68
  end
68
69
 
69
70
  # Iterative methods
70
71
  def self.stop_all
71
- @timers.values.each(&:stop)
72
+ __timers.values.each(&:stop)
72
73
  end
73
74
 
74
75
  def self.reset_all
75
- @timers.values.each(&:reset)
76
+ __timers.values.each(&:reset)
76
77
  end
77
78
 
78
79
  def self.delete_all
79
- @timers.values.each { |t| t.reset(force: true) }
80
- @timers = {}
80
+ __timers.values.each { |t| t.reset(force: true) }
81
+ Thread.current[:time_up_timers] = {}
81
82
  end
82
83
 
83
84
  # Internal methods
85
+ def self.__timers
86
+ Thread.current[:time_up_timers]
87
+ end
88
+
84
89
  def self.__ensure_timer(name)
85
- raise Error.new("No timer named #{name.inspect}") unless @timers[name]
90
+ raise Error.new("No timer named #{name.inspect}") unless __timers[name]
86
91
  end
87
92
 
88
93
  class Timer
@@ -1,3 +1,3 @@
1
1
  module TimeUp
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls