elapsed 0.0.1 → 0.2.0

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.
data/Gemfile.lock CHANGED
@@ -2,177 +2,86 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  elapsed (0.0.0)
5
- loog (> 0)
6
- tago (> 0)
5
+ loog (~> 0.6)
6
+ tago (~> 0.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionpack (7.2.0)
12
- actionview (= 7.2.0)
13
- activesupport (= 7.2.0)
14
- nokogiri (>= 1.8.5)
15
- racc
16
- rack (>= 2.2.4, < 3.2)
17
- rack-session (>= 1.0.1)
18
- rack-test (>= 0.6.3)
19
- rails-dom-testing (~> 2.2)
20
- rails-html-sanitizer (~> 1.6)
21
- useragent (~> 0.16)
22
- actionview (7.2.0)
23
- activesupport (= 7.2.0)
24
- builder (~> 3.1)
25
- erubi (~> 1.11)
26
- rails-dom-testing (~> 2.2)
27
- rails-html-sanitizer (~> 1.6)
28
- activesupport (7.2.0)
29
- base64
30
- bigdecimal
31
- concurrent-ruby (~> 1.0, >= 1.3.1)
32
- connection_pool (>= 2.2.5)
33
- drb
34
- i18n (>= 1.6, < 2)
35
- logger (>= 1.4.2)
36
- minitest (>= 5.1)
37
- securerandom (>= 0.3)
38
- tzinfo (~> 2.0, >= 2.0.5)
39
- ast (2.4.2)
40
- base64 (0.2.0)
41
- bigdecimal (3.1.8)
11
+ ansi (1.5.0)
12
+ ast (2.4.3)
42
13
  builder (3.3.0)
43
- concurrent-ruby (1.3.4)
44
- connection_pool (2.4.1)
45
- crass (1.0.6)
46
- diff-lcs (1.5.1)
47
14
  docile (1.4.1)
48
- drb (2.2.1)
49
- erubi (1.13.0)
50
- i18n (1.14.5)
51
- concurrent-ruby (~> 1.0)
52
- io-console (0.7.2)
53
- irb (1.14.0)
54
- rdoc (>= 4.0.0)
55
- reline (>= 0.4.2)
56
- json (2.7.2)
57
- language_server-protocol (3.17.0.3)
58
- logger (1.6.0)
59
- loofah (2.22.0)
60
- crass (~> 1.0.2)
61
- nokogiri (>= 1.12.0)
62
- loog (0.6.0)
63
- minitest (5.25.0)
64
- nokogiri (1.16.7-aarch64-linux)
65
- racc (~> 1.4)
66
- nokogiri (1.16.7-arm-linux)
67
- racc (~> 1.4)
68
- nokogiri (1.16.7-arm64-darwin)
69
- racc (~> 1.4)
70
- nokogiri (1.16.7-x64-mingw-ucrt)
71
- racc (~> 1.4)
72
- nokogiri (1.16.7-x86-linux)
73
- racc (~> 1.4)
74
- nokogiri (1.16.7-x86_64-darwin)
75
- racc (~> 1.4)
76
- nokogiri (1.16.7-x86_64-linux)
77
- racc (~> 1.4)
78
- parallel (1.26.2)
79
- parser (3.3.4.2)
15
+ json (2.13.2)
16
+ language_server-protocol (3.17.0.5)
17
+ lint_roller (1.1.0)
18
+ logger (1.7.0)
19
+ loog (0.6.1)
20
+ logger (~> 1.0)
21
+ minitest (5.25.5)
22
+ minitest-reporters (1.7.1)
23
+ ansi
24
+ builder
25
+ minitest (>= 5.0)
26
+ ruby-progressbar
27
+ parallel (1.27.0)
28
+ parser (3.3.9.0)
80
29
  ast (~> 2.4.1)
81
30
  racc
82
- psych (5.1.2)
83
- stringio
31
+ prism (1.4.0)
84
32
  racc (1.8.1)
85
- rack (3.1.7)
86
- rack-session (2.0.0)
87
- rack (>= 3.0.0)
88
- rack-test (2.1.0)
89
- rack (>= 1.3)
90
- rackup (2.1.0)
91
- rack (>= 3)
92
- webrick (~> 1.8)
93
- rails-dom-testing (2.2.0)
94
- activesupport (>= 5.0.0)
95
- minitest
96
- nokogiri (>= 1.6)
97
- rails-html-sanitizer (1.6.0)
98
- loofah (~> 2.21)
99
- nokogiri (~> 1.14)
100
- railties (7.2.0)
101
- actionpack (= 7.2.0)
102
- activesupport (= 7.2.0)
103
- irb (~> 1.13)
104
- rackup (>= 1.0.0)
105
- rake (>= 12.2)
106
- thor (~> 1.0, >= 1.2.2)
107
- zeitwerk (~> 2.6)
108
33
  rainbow (3.1.1)
109
- rake (13.2.1)
110
- rdoc (6.7.0)
111
- psych (>= 4.0.0)
112
- regexp_parser (2.9.2)
113
- reline (0.5.9)
114
- io-console (~> 0.5)
115
- rexml (3.3.5)
116
- strscan
117
- rspec-core (3.13.0)
118
- rspec-support (~> 3.13.0)
119
- rspec-expectations (3.13.1)
120
- diff-lcs (>= 1.2.0, < 2.0)
121
- rspec-support (~> 3.13.0)
122
- rspec-mocks (3.13.1)
123
- diff-lcs (>= 1.2.0, < 2.0)
124
- rspec-support (~> 3.13.0)
125
- rspec-rails (6.1.3)
126
- actionpack (>= 6.1)
127
- activesupport (>= 6.1)
128
- railties (>= 6.1)
129
- rspec-core (~> 3.13)
130
- rspec-expectations (~> 3.13)
131
- rspec-mocks (~> 3.13)
132
- rspec-support (~> 3.13)
133
- rspec-support (3.13.1)
134
- rubocop (1.65.1)
34
+ rake (13.3.0)
35
+ regexp_parser (2.10.0)
36
+ rexml (3.4.1)
37
+ rubocop (1.79.0)
135
38
  json (~> 2.3)
136
- language_server-protocol (>= 3.17.0)
39
+ language_server-protocol (~> 3.17.0.2)
40
+ lint_roller (~> 1.1.0)
137
41
  parallel (~> 1.10)
138
42
  parser (>= 3.3.0.2)
139
43
  rainbow (>= 2.2.2, < 4.0)
140
- regexp_parser (>= 2.4, < 3.0)
141
- rexml (>= 3.2.5, < 4.0)
142
- rubocop-ast (>= 1.31.1, < 2.0)
44
+ regexp_parser (>= 2.9.3, < 3.0)
45
+ rubocop-ast (>= 1.46.0, < 2.0)
143
46
  ruby-progressbar (~> 1.7)
144
- unicode-display_width (>= 2.4.0, < 3.0)
145
- rubocop-ast (1.32.0)
146
- parser (>= 3.3.1.0)
147
- rubocop-rspec (3.0.4)
148
- rubocop (~> 1.61)
47
+ tsort (>= 0.2.0)
48
+ unicode-display_width (>= 2.4.0, < 4.0)
49
+ rubocop-ast (1.46.0)
50
+ parser (>= 3.3.7.2)
51
+ prism (~> 1.4)
52
+ rubocop-minitest (0.38.1)
53
+ lint_roller (~> 1.1)
54
+ rubocop (>= 1.75.0, < 2.0)
55
+ rubocop-ast (>= 1.38.0, < 2.0)
56
+ rubocop-performance (1.25.0)
57
+ lint_roller (~> 1.1)
58
+ rubocop (>= 1.75.0, < 2.0)
59
+ rubocop-ast (>= 1.38.0, < 2.0)
60
+ rubocop-rake (0.7.1)
61
+ lint_roller (~> 1.1)
62
+ rubocop (>= 1.72.1)
149
63
  ruby-progressbar (1.13.0)
150
- securerandom (0.3.1)
151
64
  simplecov (0.22.0)
152
65
  docile (~> 1.1)
153
66
  simplecov-html (~> 0.11)
154
67
  simplecov_json_formatter (~> 0.1)
155
- simplecov-cobertura (2.1.0)
68
+ simplecov-cobertura (3.0.0)
156
69
  rexml
157
70
  simplecov (~> 0.19)
158
- simplecov-html (0.12.3)
71
+ simplecov-html (0.13.2)
159
72
  simplecov_json_formatter (0.1.4)
160
- stringio (3.1.1)
161
- strscan (3.1.0)
162
- tago (0.0.2)
163
- thor (1.3.1)
164
- tzinfo (2.0.6)
165
- concurrent-ruby (~> 1.0)
166
- unicode-display_width (2.5.0)
167
- useragent (0.16.10)
168
- webrick (1.8.1)
169
- yard (0.9.36)
170
- zeitwerk (2.6.17)
73
+ tago (0.1.0)
74
+ tsort (0.2.0)
75
+ unicode-display_width (3.1.4)
76
+ unicode-emoji (~> 4.0, >= 4.0.4)
77
+ unicode-emoji (4.0.4)
78
+ yard (0.9.37)
171
79
 
172
80
  PLATFORMS
173
81
  aarch64-linux
174
82
  arm-linux
175
83
  arm64-darwin
84
+ arm64-darwin-23
176
85
  x64-mingw-ucrt
177
86
  x86-linux
178
87
  x86_64-darwin
@@ -180,14 +89,16 @@ PLATFORMS
180
89
 
181
90
  DEPENDENCIES
182
91
  elapsed!
183
- minitest (= 5.25.0)
184
- rake (= 13.2.1)
185
- rspec-rails (= 6.1.3)
186
- rubocop (= 1.65.1)
187
- rubocop-rspec (= 3.0.4)
188
- simplecov (= 0.22.0)
189
- simplecov-cobertura (= 2.1.0)
190
- yard (= 0.9.36)
92
+ minitest (~> 5.25)
93
+ minitest-reporters (~> 1.7)
94
+ rake (~> 13.2)
95
+ rubocop (~> 1.69)
96
+ rubocop-minitest (~> 0.38)
97
+ rubocop-performance (~> 1.25)
98
+ rubocop-rake (~> 0.7)
99
+ simplecov (~> 0.22)
100
+ simplecov-cobertura (~> 3.0)
101
+ yard (~> 0.9)
191
102
 
192
103
  BUNDLED WITH
193
104
  2.5.16
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2024 Yegor Bugayenko
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/LICENSES/MIT.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Measures the Time Elapsed by a Block
2
2
 
3
- [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/elapsed)](http://www.rultor.com/p/yegor256/elapsed)
3
+ [![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/elapsed)](https://www.rultor.com/p/yegor256/elapsed)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
5
 
6
6
  [![rake](https://github.com/yegor256/elapsed/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/elapsed/actions/workflows/rake.yml)
7
- [![PDD status](http://www.0pdd.com/svg?name=yegor256/elapsed)](http://www.0pdd.com/p?name=yegor256/elapsed)
8
- [![Gem Version](https://badge.fury.io/rb/elapsed.svg)](http://badge.fury.io/rb/elapsed)
7
+ [![PDD status](https://www.0pdd.com/svg?name=yegor256/elapsed)](https://www.0pdd.com/p?name=yegor256/elapsed)
8
+ [![Gem Version](https://badge.fury.io/rb/elapsed.svg)](https://badge.fury.io/rb/elapsed)
9
9
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/elapsed.svg)](https://codecov.io/github/yegor256/elapsed?branch=master)
10
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/elapsed/master/frames)
10
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/elapsed/master/frames)
11
11
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/elapsed)](https://hitsofcode.com/view/github/yegor256/elapsed)
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/elapsed/blob/master/LICENSE.txt)
13
13
 
@@ -34,7 +34,7 @@ end
34
34
  You can also make the message custom:
35
35
 
36
36
  ```ruby
37
- elapsed(intro: 'File saved') do
37
+ elapsed(good: 'File saved') do
38
38
  File.save(f, 'Hello, world!')
39
39
  end
40
40
  ```
@@ -48,13 +48,22 @@ elapsed do
48
48
  end
49
49
  ```
50
50
 
51
+ You can also filter out small durations using the `over:` parameter:
52
+
53
+ ```ruby
54
+ elapsed(Loog::VERBOSE, over: 0.5) do
55
+ # This message will only be logged if the block takes more than 0.5 seconds
56
+ run_something_that_might_be_fast
57
+ end
58
+ ```
59
+
51
60
  That's it.
52
61
 
53
62
  ## How to contribute
54
63
 
55
64
  Read
56
65
  [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
57
- Make sure you build is green before you contribute
66
+ Make sure your build is green before you contribute
58
67
  your pull request. You will need to have
59
68
  [Ruby](https://www.ruby-lang.org/en/) 3.0+ and
60
69
  [Bundler](https://bundler.io/) installed. Then:
data/REUSE.toml ADDED
@@ -0,0 +1,34 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ version = 1
5
+ [[annotations]]
6
+ path = [
7
+ ".DS_Store",
8
+ ".gitattributes",
9
+ ".gitignore",
10
+ ".pdd",
11
+ "**.json",
12
+ "**.md",
13
+ "**.txt",
14
+ "**/.DS_Store",
15
+ "**/.gitignore",
16
+ "**/.pdd",
17
+ "**/*.csv",
18
+ "**/*.jpg",
19
+ "**/*.json",
20
+ "**/*.md",
21
+ "**/*.pdf",
22
+ "**/*.png",
23
+ "**/*.svg",
24
+ "**/*.txt",
25
+ "**/*.vm",
26
+ "**/CNAME",
27
+ "**/Gemfile.lock",
28
+ "Gemfile.lock",
29
+ "README.md",
30
+ "renovate.json",
31
+ ]
32
+ precedence = "override"
33
+ SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
34
+ SPDX-License-Identifier = "MIT"
data/Rakefile CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
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 all
13
- # 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 THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'rubygems'
24
7
  require 'rake'
@@ -33,7 +16,7 @@ def version
33
16
  Gem::Specification.load(Dir['*.gemspec'].first).version
34
17
  end
35
18
 
36
- task default: %i[clean test rubocop yard copyright]
19
+ task default: %i[clean test rubocop yard]
37
20
 
38
21
  require 'rake/testtask'
39
22
  desc 'Run all unit tests'
@@ -55,14 +38,4 @@ require 'rubocop/rake_task'
55
38
  desc 'Run RuboCop on all directories'
56
39
  RuboCop::RakeTask.new(:rubocop) do |task|
57
40
  task.fail_on_error = true
58
- task.requires << 'rubocop-rspec'
59
- end
60
-
61
- task :copyright do
62
- sh "grep -q -r '#{Date.today.strftime('%Y')}' \
63
- --include '*.rb' \
64
- --include '*.yml' \
65
- --include '*.txt' \
66
- --include 'Rakefile' \
67
- ."
68
41
  end
data/elapsed.gemspec CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
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 all
13
- # 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 THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'English'
24
7
 
@@ -26,7 +9,7 @@ Gem::Specification.new do |s|
26
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
27
10
  s.required_ruby_version = '>=3.2'
28
11
  s.name = 'elapsed'
29
- s.version = '0.0.1'
12
+ s.version = '0.2.0'
30
13
  s.license = 'MIT'
31
14
  s.summary = 'A simple Ruby function to measure the time elapsed by the execution of a block'
32
15
  s.description =
@@ -34,12 +17,12 @@ Gem::Specification.new do |s|
34
17
  'print the summary of execution to the log with the time it took'
35
18
  s.authors = ['Yegor Bugayenko']
36
19
  s.email = 'yegor256@gmail.com'
37
- s.homepage = 'http://github.com/yegor256/elapsed'
20
+ s.homepage = 'https://github.com/yegor256/elapsed'
38
21
  s.files = `git ls-files`.split($RS)
39
22
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
40
23
  s.rdoc_options = ['--charset=UTF-8']
41
24
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
42
- s.add_dependency 'loog', '>0'
43
- s.add_dependency 'tago', '>0'
25
+ s.add_dependency 'loog', '~>0.6'
26
+ s.add_dependency 'tago', '~>0.1'
44
27
  s.metadata['rubygems_mfa_required'] = 'true'
45
28
  end
data/lib/elapsed.rb CHANGED
@@ -1,29 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
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 all
13
- # 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 THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'logger'
24
7
  require 'tago'
25
8
 
26
- # The function measures the time taked by a block to execute and then prints
9
+ # The function measures the time taken by a block to execute and then prints
27
10
  # it to the log.
28
11
  #
29
12
  # require 'elapsed'
@@ -33,40 +16,41 @@ require 'tago'
33
16
  # end
34
17
  #
35
18
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
36
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
19
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
37
20
  # License:: MIT
38
21
  #
39
22
  # @param [Object] log The log to send .debug() to
40
- # @param [String] intro The message to start with
23
+ # @param [String] good The message to print on success finish
24
+ # @param [String] bad The message to print on failure finish
41
25
  # @param [Integer] level The level of logging to use
42
- def elapsed(log = nil, intro: 'Finished', level: Logger::DEBUG)
26
+ # @param [Float] over The minimum duration in seconds to report
27
+ def elapsed(log = nil, good: 'Finished', level: Logger::DEBUG, bad: 'Failed', over: 0)
43
28
  start = Time.now
44
- begin
45
- ret = yield
46
- msg = intro.to_s
47
- msg += " in #{start.ago}"
29
+ print_it = lambda do |m|
30
+ duration = Time.now - start
31
+ return if duration < over
32
+
33
+ m += " in #{start.ago}"
48
34
  if log.nil?
49
- puts msg
35
+ puts m
50
36
  elsif level == Logger::DEBUG
51
- log.debug(msg)
37
+ log.debug(m)
52
38
  elsif level == Logger::INFO
53
- log.info(msg)
39
+ log.info(m)
54
40
  else
55
- log.warn(msg)
41
+ log.warn(m)
56
42
  end
43
+ end
44
+ begin
45
+ ret = yield
46
+ print_it.call(good.to_s)
57
47
  ret
58
48
  rescue UncaughtThrowError => e
59
49
  tag = e.tag
60
50
  throw e unless tag.is_a?(Symbol)
61
- msg = "#{tag} in #{start.ago}"
62
- if log.nil?
63
- puts msg
64
- elsif level == Logger::DEBUG
65
- log.debug(msg)
66
- elsif level == Logger::INFO
67
- log.info(msg)
68
- else
69
- log.warn(msg)
70
- end
51
+ print_it.call(tag.to_s)
52
+ rescue StandardError => e
53
+ print_it.call(bad.to_s)
54
+ raise e
71
55
  end
72
56
  end
data/test/test__helper.rb CHANGED
@@ -1,31 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
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 all
13
- # 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 THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  $stdout.sync = true
24
7
 
25
8
  require 'simplecov'
26
- SimpleCov.start
27
-
28
9
  require 'simplecov-cobertura'
29
- SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
10
+ unless SimpleCov.running
11
+ SimpleCov.command_name('test')
12
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
13
+ [
14
+ SimpleCov::Formatter::HTMLFormatter,
15
+ SimpleCov::Formatter::CoberturaFormatter
16
+ ]
17
+ )
18
+ SimpleCov.minimum_coverage 100
19
+ SimpleCov.minimum_coverage_by_file 100
20
+ SimpleCov.start do
21
+ add_filter 'test/'
22
+ add_filter 'vendor/'
23
+ add_filter 'target/'
24
+ track_files 'lib/**/*.rb'
25
+ track_files '*.rb'
26
+ end
27
+ end
30
28
 
31
29
  require 'minitest/autorun'
30
+ require 'minitest/reporters'
31
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]