console 1.15.3 → 1.16.2

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.
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require_relative 'generic'
24
- require_relative '../clock'
25
-
26
- module Console
27
- module Event
28
- class Metric < Generic
29
- def self.[](**parameters)
30
- parameters.map(&self.method(:new))
31
- end
32
-
33
- def initialize(name, value, **tags)
34
- @name = name
35
- @value = value
36
- @tags = tags
37
- end
38
-
39
- attr :name
40
- attr :value
41
- attr :tags
42
-
43
- def to_h
44
- {name: @name, value: @value, tags: @tags}
45
- end
46
-
47
- def value_string
48
- "#{@name}: #{@value}"
49
- end
50
-
51
- def format(output, terminal, verbose)
52
- if @tags&.any?
53
- output.puts "#{value_string} #{@tags.inspect}"
54
- else
55
- output.puts value_string
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require_relative 'event/measure'
24
- require_relative 'clock'
25
-
26
- module Console
27
- class Measure
28
- def initialize(output, subject, **tags)
29
- @output = output
30
- @subject = subject
31
- @tags = tags
32
- end
33
-
34
- attr :tags
35
-
36
- # Measure the execution of a block of code.
37
- def duration(name, &block)
38
- @output.info(@subject) {Event::Enter.new(name)}
39
-
40
- start_time = Clock.now
41
-
42
- result = yield(self)
43
-
44
- duration = Clock.now - start_time
45
-
46
- @output.info(@subject) {Event::Exit.new(name, duration, **@tags)}
47
-
48
- return result
49
- end
50
- end
51
- end