console 1.11.0 → 1.11.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: 5928a2a5d4c07c44e8ad937edbab2b8fa326ff13553ffb4bf89c0854184f1bd8
4
- data.tar.gz: e0495d1933a3a0991b23193aae3988fb679389f02514d57c9a15ce7ccbf73497
3
+ metadata.gz: 149a9d0738e731ea3ef3159cd25a449f663070406dfa232538a5996fb93c9ce9
4
+ data.tar.gz: 212772395d4aef7dc7a510d6630e11dfabeb4c8cf2c70f5d272c279a3d2a32ef
5
5
  SHA512:
6
- metadata.gz: e69af353f0397d3620654d9108b2cb7fffe4d601e4a4f9feea7cdf09a7cd40aa3f310faded79abfc8de5735c257b59713bb9d5a91d5320a1dca15d0df4a92804
7
- data.tar.gz: c46ec0e33e56260345710facc882d89edb4782179ccdb7ec97ed70c3d83087465b4758ceecdaa7f8ac4e2508dc18f46968974bee19a694c62c5314157a8402fe
6
+ metadata.gz: d02021cfb6dbf99651d5f1b8653394dd59f2c830b0a62b8c394b70b275030cd2c066a786a9cb1281df55029f9a69455c00a73a1763785cba3a5ccf8769766654
7
+ data.tar.gz: be05f291ccae55c3a6cce6ed2e5e79fa968682d856bcc502693408c69cc85b563017e8505a0459f6cb0d628bbdc57b58efd28146b460e09b45695652e6263145
@@ -74,14 +74,14 @@ module Console
74
74
  Progress.new(self, subject, total, **options)
75
75
  end
76
76
 
77
- def measure(subject, name = "block", **options, &block)
78
- measure = Measure.new(self, subject)
77
+ def measure(subject, name = "block", **tags, &block)
78
+ measure = Measure.new(self, subject, **tags)
79
79
 
80
80
  if block_given?
81
- measure.duration(name, **options, &block)
81
+ return measure.duration(name, &block)
82
+ else
83
+ return measure
82
84
  end
83
-
84
- return measure
85
85
  end
86
86
 
87
87
  def failure(subject, exception, *arguments, &block)
@@ -23,24 +23,27 @@ require_relative 'clock'
23
23
 
24
24
  module Console
25
25
  class Measure
26
- def initialize(output, subject)
26
+ def initialize(output, subject, **tags)
27
27
  @output = output
28
28
  @subject = subject
29
+ @tags = tags
29
30
  end
30
31
 
32
+ attr :tags
33
+
31
34
  # Measure the execution of a block of code.
32
- def duration(name, **tags, &block)
35
+ def duration(name, &block)
33
36
  @output.info(@subject) {Event::Enter.new(name)}
34
37
 
35
38
  start_time = Clock.now
36
39
 
37
- yield
40
+ result = yield(self)
38
41
 
39
42
  duration = Clock.now - start_time
40
43
 
41
- @output.info(@subject) {Event::Exit.new(name, duration, **tags)}
44
+ @output.info(@subject) {Event::Exit.new(name, duration, **@tags)}
42
45
 
43
- return duration
46
+ return result
44
47
  end
45
48
  end
46
49
  end
@@ -19,6 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require_relative 'event/progress'
22
+ require_relative 'clock'
22
23
 
23
24
  module Console
24
25
  class Progress
@@ -93,7 +94,7 @@ module Console
93
94
 
94
95
  def to_s
95
96
  if estimated_remaining_time = self.estimated_remaining_time
96
- "#{@current}/#{@total} completed in #{formatted_duration(self.duration)}, #{formatted_duration(estimated_remaining_time)} remaining."
97
+ "#{@current}/#{@total} completed in #{Clock.formatted_duration(self.duration)}, #{Clock.formatted_duration(estimated_remaining_time)} remaining."
97
98
  else
98
99
  "#{@current}/#{@total} completed, waiting for estimate..."
99
100
  end
@@ -116,27 +117,5 @@ module Console
116
117
  return true
117
118
  end
118
119
  end
119
-
120
- def formatted_duration(duration)
121
- if duration < 60.0
122
- return "#{duration.round(2)}s"
123
- end
124
-
125
- duration /= 60.0
126
-
127
- if duration < 60.0
128
- return "#{duration.round}m"
129
- end
130
-
131
- duration /= 60.0
132
-
133
- if duration < 60.0
134
- return "#{duration.round(1)}h"
135
- end
136
-
137
- duration /= 24.0
138
-
139
- return "#{duration.round(1)}d"
140
- end
141
120
  end
142
121
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Console
22
- VERSION = "1.11.0"
22
+ VERSION = "1.11.1"
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams