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 +4 -4
- data/lib/console/logger.rb +5 -5
- data/lib/console/measure.rb +8 -5
- data/lib/console/progress.rb +2 -23
- data/lib/console/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 149a9d0738e731ea3ef3159cd25a449f663070406dfa232538a5996fb93c9ce9
|
4
|
+
data.tar.gz: 212772395d4aef7dc7a510d6630e11dfabeb4c8cf2c70f5d272c279a3d2a32ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d02021cfb6dbf99651d5f1b8653394dd59f2c830b0a62b8c394b70b275030cd2c066a786a9cb1281df55029f9a69455c00a73a1763785cba3a5ccf8769766654
|
7
|
+
data.tar.gz: be05f291ccae55c3a6cce6ed2e5e79fa968682d856bcc502693408c69cc85b563017e8505a0459f6cb0d628bbdc57b58efd28146b460e09b45695652e6263145
|
data/lib/console/logger.rb
CHANGED
@@ -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", **
|
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,
|
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)
|
data/lib/console/measure.rb
CHANGED
@@ -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,
|
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,
|
44
|
+
@output.info(@subject) {Event::Exit.new(name, duration, **@tags)}
|
42
45
|
|
43
|
-
return
|
46
|
+
return result
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
data/lib/console/progress.rb
CHANGED
@@ -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
|
data/lib/console/version.rb
CHANGED