random-port 0.8.0 → 0.8.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd90fdffc75dd2489cab29b75ddadb118d7399fc51acf86d0c7588cff3656bef
4
- data.tar.gz: f8f40a67dd0fd7daf6fd7ad67e9272035a587b96dbaf581777f659a3d1779bd3
3
+ metadata.gz: 165b26f62adb64a8b809949e3082e272bad1b6c91b724a90ae95dd9d8c20b41f
4
+ data.tar.gz: b7a5cbc43e59e72712008bba02a045d788e160bb1b464c261c6b12b8b26da56e
5
5
  SHA512:
6
- metadata.gz: 9b076ebfe2d5b5ec19a2252783e2e1d01050feebb698d5ef1066aefbb230708617fabba95f9a363b3c6dc03204ce8eb7de92d1d902c572374f69d7d1c979e9d5
7
- data.tar.gz: c6f56a56d9b510904a982a78ed9e2cab315cdd8d5e21a0587ac3aae10c9da9e1435ebbf1bd888d92a0f34930b3032f99febcaae593268988685ea060ba2db70c
6
+ metadata.gz: 47163bd973670922d0dc4d85210670d95a50af2e2fcf6c50ed5a19cf14c55b394929fafb55b511f22762cccda36a66f74b4ccc695628ec2b16768d043772ee80
7
+ data.tar.gz: a469ec037ab1bc015672beb7edcd68a6a6a401e16b0ece0086a41b8103245418d37bc8eddf1d4fad241f622f6c68fcdb564d39e38434a254c0501025c3f1a29f
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ gemspec
9
9
  gem 'minitest', '~>6.0', require: false
10
10
  gem 'minitest-mock', '~>5.27', require: false
11
11
  gem 'minitest-reporters', '~>1.7', require: false
12
+ gem 'os', '~> 1.1', require: false
12
13
  gem 'qbash', '~>0.2', require: false
13
14
  gem 'rake', '~>13.2', require: false
14
15
  gem 'rubocop', '~>1.75', require: false
data/Gemfile.lock CHANGED
@@ -13,15 +13,15 @@ GEM
13
13
  builder (3.3.0)
14
14
  concurrent-ruby (1.3.6)
15
15
  docile (1.4.1)
16
- elapsed (0.2.2)
16
+ elapsed (0.3.1)
17
17
  loog (~> 0.6)
18
18
  tago (~> 0.1)
19
19
  ellipsized (0.3.0)
20
- json (2.18.0)
20
+ json (2.18.1)
21
21
  language_server-protocol (3.17.0.5)
22
22
  lint_roller (1.1.0)
23
23
  logger (1.7.0)
24
- loog (0.7.2)
24
+ loog (0.8.0)
25
25
  ellipsized
26
26
  logger (~> 1.0)
27
27
  minitest (6.0.1)
@@ -32,11 +32,12 @@ GEM
32
32
  builder
33
33
  minitest (>= 5.0)
34
34
  ruby-progressbar
35
+ os (1.1.4)
35
36
  parallel (1.27.0)
36
37
  parser (3.3.10.1)
37
38
  ast (~> 2.4.1)
38
39
  racc
39
- prism (1.8.0)
40
+ prism (1.9.0)
40
41
  qbash (0.7.2)
41
42
  backtrace (> 0)
42
43
  elapsed (> 0)
@@ -47,7 +48,7 @@ GEM
47
48
  rake (13.3.1)
48
49
  regexp_parser (2.11.3)
49
50
  rexml (3.4.4)
50
- rubocop (1.84.1)
51
+ rubocop (1.84.2)
51
52
  json (~> 2.3)
52
53
  language_server-protocol (~> 3.17.0.2)
53
54
  lint_roller (~> 1.1.0)
@@ -105,6 +106,7 @@ DEPENDENCIES
105
106
  minitest (~> 6.0)
106
107
  minitest-mock (~> 5.27)
107
108
  minitest-reporters (~> 1.7)
109
+ os (~> 1.1)
108
110
  qbash (~> 0.2)
109
111
  rake (~> 13.2)
110
112
  random-port!
data/README.md CHANGED
@@ -5,7 +5,6 @@
5
5
 
6
6
  [![rake](https://github.com/yegor256/random-port/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/random-port/actions/workflows/rake.yml)
7
7
  [![Gem Version](https://badge.fury.io/rb/random-port.svg)](https://badge.fury.io/rb/random-port)
8
- [![Maintainability](https://api.codeclimate.com/v1/badges/349b8c31884d3b34d926/maintainability)](https://codeclimate.com/github/yegor256/random-port/maintainability)
9
8
  [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/random-port/master/frames)
10
9
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/random-port/blob/master/LICENSE.txt)
11
10
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/random-port.svg)](https://codecov.io/github/yegor256/random-port?branch=master)
@@ -26,8 +25,8 @@ require 'random-port'
26
25
  port = RandomPort::Pool.new.acquire
27
26
  ```
28
27
 
29
- The `Pool` guarantees that the port won't be used again. You can put
30
- the port back to the pool after usage:
28
+ The `Pool` guarantees that the port isn't used again.
29
+ You can put the port back to the pool after usage:
31
30
 
32
31
  ```ruby
33
32
  RandomPort::Pool.new.acquire do |port|
@@ -53,7 +52,7 @@ end
53
52
  ```
54
53
 
55
54
  Or use shortened version, all methods called in `RandomPort`
56
- will be delegated to `Pool::SINGLETON`:
55
+ are delegated to `Pool::SINGLETON`:
57
56
 
58
57
  ```ruby
59
58
  RandomPort.acquire do |port|
@@ -62,17 +61,15 @@ end
62
61
  ```
63
62
 
64
63
  The pool is thread-safe by default.
65
- You can configure it to be
66
- not-thread-safe, using optional `sync` argument of the constructor.
64
+ You can configure it to be not-thread-safe,
65
+ using optional `sync` argument of the constructor.
67
66
 
68
67
  ## How to contribute
69
68
 
70
- Read
71
- [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
72
- Make sure your build is green before you contribute
73
- your pull request. You will need to have
74
- [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
75
- [Bundler](https://bundler.io/) installed. Then:
69
+ Read these [guidelines].
70
+ Make sure your build is green before you contribute your pull request.
71
+ You need to have [Ruby] 3.3+ and [Bundler] installed.
72
+ Then:
76
73
 
77
74
  ```bash
78
75
  bundle update
@@ -80,3 +77,7 @@ bundle exec rake
80
77
  ```
81
78
 
82
79
  If it's clean and you don't see any error messages, submit your pull request.
80
+
81
+ [guidelines]: https://www.yegor256.com/2014/04/15/github-guidelines.html
82
+ [Ruby]: https://www.ruby-lang.org/en/
83
+ [Bundler]: https://bundler.io/
data/REUSE.toml CHANGED
@@ -5,8 +5,6 @@ version = 1
5
5
  [[annotations]]
6
6
  path = [
7
7
  ".DS_Store",
8
- ".gitattributes",
9
- ".gitignore",
10
8
  ".pdd",
11
9
  "**.json",
12
10
  "**.md",
data/Rakefile CHANGED
@@ -3,9 +3,12 @@
3
3
  # SPDX-FileCopyrightText: Copyright (c) 2018-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
+ require 'os'
7
+ require 'qbash'
6
8
  require 'rubygems'
7
9
  require 'rake'
8
10
  require 'rake/clean'
11
+ require 'shellwords'
9
12
 
10
13
  CLEAN << 'coverage'
11
14
 
@@ -17,7 +20,7 @@ def version
17
20
  Gem::Specification.load(Dir['*.gemspec'].first).version
18
21
  end
19
22
 
20
- task default: %i[clean test yard rubocop]
23
+ task default: %i[clean test picks yard rubocop]
21
24
 
22
25
  require 'rake/testtask'
23
26
  desc 'Run all unit tests'
@@ -27,6 +30,16 @@ Rake::TestTask.new(:test) do |test|
27
30
  test.verbose = false
28
31
  end
29
32
 
33
+ desc 'Run them via Ruby, one by one'
34
+ task :picks do
35
+ next if OS.windows?
36
+ %w[test lib].each do |d|
37
+ Dir["#{d}/**/*.rb"].each do |f|
38
+ qbash("bundle exec ruby #{Shellwords.escape(f)}", stdout: $stdout, env: { 'PICKS' => 'yes' })
39
+ end
40
+ end
41
+ end
42
+
30
43
  require 'rubocop/rake_task'
31
44
  desc 'Run RuboCop on all directories'
32
45
  RuboCop::RakeTask.new(:rubocop) do |task|
@@ -3,6 +3,8 @@
3
3
  # SPDX-FileCopyrightText: Copyright (c) 2018-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
+ require 'forwardable'
7
+
6
8
  # Main module that contains all RandomPort classes and utilities.
7
9
  #
8
10
  # This module provides a simple way to acquire random TCP ports
@@ -134,7 +134,7 @@ class RandomPort::Pool
134
134
  end
135
135
  return nil if opts.any? { |p| @ports.include?(p) }
136
136
  d = total * (total - 1) / 2
137
- return nil unless opts.inject(&:+) - (total * opts.min) == d
137
+ return nil unless opts.sum - (total * opts.min) == d
138
138
  @ports += opts
139
139
  opts
140
140
  end
@@ -150,21 +150,19 @@ class RandomPort::Pool
150
150
  # @raise [SocketError] If there's a socket-related error
151
151
  def take(port)
152
152
  ['127.0.0.1', '::1', '0.0.0.0', 'localhost'].each do |host|
153
- begin
154
- TCPServer.new(host, port).close
155
- rescue Errno::EADDRNOTAVAIL
156
- next
157
- end
153
+ TCPServer.new(host, port).close
154
+ rescue Errno::EADDRNOTAVAIL
155
+ next
158
156
  end
159
157
  port
160
158
  end
161
159
 
162
160
  # Executes a block of code with or without thread synchronization.
163
- # @param block The block of code to execute
161
+ # @yield The block of code to execute
164
162
  # @return The result of the block execution
165
- def safe(&block)
163
+ def safe(&)
166
164
  if @sync
167
- @monitor.synchronize(&block)
165
+ @monitor.synchronize(&)
168
166
  else
169
167
  yield
170
168
  end
data/random-port.gemspec CHANGED
@@ -6,9 +6,9 @@
6
6
  require 'English'
7
7
  Gem::Specification.new do |s|
8
8
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
9
- s.required_ruby_version = '>=2.3'
9
+ s.required_ruby_version = '>=3.3'
10
10
  s.name = 'random-port'
11
- s.version = '0.8.0'
11
+ s.version = '0.8.2'
12
12
  s.license = 'MIT'
13
13
  s.summary = 'Random TCP port'
14
14
  s.description = 'Reserves a random TCP port'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random-port
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -54,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: '2.3'
57
+ version: '3.3'
58
58
  required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="