random-port 0.8.2 → 0.8.3

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: 165b26f62adb64a8b809949e3082e272bad1b6c91b724a90ae95dd9d8c20b41f
4
- data.tar.gz: b7a5cbc43e59e72712008bba02a045d788e160bb1b464c261c6b12b8b26da56e
3
+ metadata.gz: e50a54cd0f5cc4a719500af4b3b8184f3ed16613c6b34c2680fa27a373907b43
4
+ data.tar.gz: d4fa618c58dda21879ebda7344153ac9b92f63434ec7b9a380063a2d908120f4
5
5
  SHA512:
6
- metadata.gz: 47163bd973670922d0dc4d85210670d95a50af2e2fcf6c50ed5a19cf14c55b394929fafb55b511f22762cccda36a66f74b4ccc695628ec2b16768d043772ee80
7
- data.tar.gz: a469ec037ab1bc015672beb7edcd68a6a6a401e16b0ece0086a41b8103245418d37bc8eddf1d4fad241f622f6c68fcdb564d39e38434a254c0501025c3f1a29f
6
+ metadata.gz: 7860cbb767a8b2d8646addd5c33a2881fea122a3b1ebb8e1729b22afbbcc5513de4b2e60e0e6e3744d08685d0798f41af3a0fed2bf61521ba75e788b66a7dd4d
7
+ data.tar.gz: b55047366c5854d1e19eb9c2009c09a6bcff868e0e05b6228768c5cf959b9c144842f42e12b08a1bed719c721bf698c6f674d36429e65b99ead9b3417093d079
data/Gemfile CHANGED
@@ -13,11 +13,12 @@ gem 'os', '~> 1.1', require: false
13
13
  gem 'qbash', '~>0.2', require: false
14
14
  gem 'rake', '~>13.2', require: false
15
15
  gem 'rubocop', '~>1.75', require: false
16
+ gem 'rubocop-elegant', '~>0.5', require: false
16
17
  gem 'rubocop-minitest', '~>0.38', require: false
17
18
  gem 'rubocop-performance', '~>1.25', require: false
18
19
  gem 'rubocop-rake', '~>0.7', require: false
19
20
  gem 'rubocop-rspec', '~> 3.7', require: false
20
- gem 'simplecov', '~>0.22', require: false
21
- gem 'simplecov-cobertura', '~>3.0', require: false
21
+ gem 'simplecov', '~>1.0', require: false
22
+ gem 'simplecov-cobertura', '~>4.0', require: false
22
23
  gem 'threads', '~>0.4', require: false
23
24
  gem 'yard', '~>0.9', require: false
data/Gemfile.lock CHANGED
@@ -7,93 +7,95 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- ansi (1.5.0)
10
+ ansi (1.6.0)
11
11
  ast (2.4.3)
12
12
  backtrace (0.4.1)
13
13
  builder (3.3.0)
14
- concurrent-ruby (1.3.6)
15
- docile (1.4.1)
14
+ concurrent-ruby (1.3.8)
15
+ drb (2.2.3)
16
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.1)
21
- language_server-protocol (3.17.0.5)
20
+ json (3.2.0)
21
+ language_server-protocol (3.17.0.6)
22
22
  lint_roller (1.1.0)
23
23
  logger (1.7.0)
24
24
  loog (0.8.0)
25
25
  ellipsized
26
26
  logger (~> 1.0)
27
- minitest (6.0.1)
28
- prism (~> 1.5)
27
+ minitest (6.1.0)
28
+ drb (~> 2.0)
29
+ prism (>= 1.5, < 3)
29
30
  minitest-mock (5.27.0)
30
- minitest-reporters (1.7.1)
31
+ minitest-reporters (1.8.0)
31
32
  ansi
32
33
  builder
33
- minitest (>= 5.0)
34
+ minitest (>= 5.0, < 7)
34
35
  ruby-progressbar
35
36
  os (1.1.4)
36
- parallel (1.27.0)
37
- parser (3.3.10.1)
37
+ parallel (2.3.0)
38
+ parser (3.3.14.0)
38
39
  ast (~> 2.4.1)
39
40
  racc
40
41
  prism (1.9.0)
41
- qbash (0.7.2)
42
+ qbash (0.8.4)
42
43
  backtrace (> 0)
43
44
  elapsed (> 0)
44
45
  loog (> 0)
45
46
  tago (> 0)
46
47
  racc (1.8.1)
47
48
  rainbow (3.1.1)
48
- rake (13.3.1)
49
- regexp_parser (2.11.3)
49
+ rake (13.4.2)
50
+ regexp_parser (2.13.4)
50
51
  rexml (3.4.4)
51
- rubocop (1.84.2)
52
- json (~> 2.3)
52
+ rubocop (1.93.0)
53
+ json (>= 2.3)
53
54
  language_server-protocol (~> 3.17.0.2)
54
55
  lint_roller (~> 1.1.0)
55
- parallel (~> 1.10)
56
+ parallel (>= 1.10)
56
57
  parser (>= 3.3.0.2)
57
58
  rainbow (>= 2.2.2, < 4.0)
58
- regexp_parser (>= 2.9.3, < 3.0)
59
- rubocop-ast (>= 1.49.0, < 2.0)
59
+ regexp_parser (>= 2.11.3, < 3.0)
60
+ rubocop-ast (>= 1.54.0, < 2.0)
60
61
  ruby-progressbar (~> 1.7)
61
62
  unicode-display_width (>= 2.4.0, < 4.0)
62
- rubocop-ast (1.49.0)
63
+ rubocop-ast (1.54.0)
64
+ ast (~> 2.4)
63
65
  parser (>= 3.3.7.2)
64
- prism (~> 1.7)
65
- rubocop-minitest (0.38.2)
66
+ prism (>= 1.7)
67
+ racc
68
+ rubocop-elegant (0.8.0)
69
+ lint_roller (~> 1.1)
70
+ rubocop (~> 1.75)
71
+ rubocop-minitest (0.41.0)
66
72
  lint_roller (~> 1.1)
67
- rubocop (>= 1.75.0, < 2.0)
73
+ rubocop (>= 1.89.0, < 2.0)
68
74
  rubocop-ast (>= 1.38.0, < 2.0)
69
- rubocop-performance (1.26.1)
75
+ rubocop-performance (1.27.0)
70
76
  lint_roller (~> 1.1)
71
- rubocop (>= 1.75.0, < 2.0)
77
+ rubocop (>= 1.89.0, < 2.0)
72
78
  rubocop-ast (>= 1.47.1, < 2.0)
73
79
  rubocop-rake (0.7.1)
74
80
  lint_roller (~> 1.1)
75
81
  rubocop (>= 1.72.1)
76
- rubocop-rspec (3.9.0)
82
+ rubocop-rspec (3.10.2)
77
83
  lint_roller (~> 1.1)
78
- rubocop (~> 1.81)
84
+ regexp_parser (>= 2.0)
85
+ rubocop (~> 1.86, >= 1.86.2)
79
86
  ruby-progressbar (1.13.0)
80
- simplecov (0.22.0)
81
- docile (~> 1.1)
82
- simplecov-html (~> 0.11)
83
- simplecov_json_formatter (~> 0.1)
84
- simplecov-cobertura (3.1.0)
87
+ simplecov (1.3.2)
88
+ simplecov-cobertura (4.0.0)
85
89
  rexml
86
- simplecov (~> 0.19)
87
- simplecov-html (0.13.2)
88
- simplecov_json_formatter (0.1.4)
90
+ simplecov (~> 1.0)
89
91
  tago (0.7.0)
90
92
  threads (0.5.0)
91
93
  backtrace (~> 0)
92
94
  concurrent-ruby (~> 1.0)
93
- unicode-display_width (3.2.0)
94
- unicode-emoji (~> 4.1)
95
- unicode-emoji (4.2.0)
96
- yard (0.9.38)
95
+ unicode-display_width (3.3.0)
96
+ unicode-emoji (~> 4.3)
97
+ unicode-emoji (4.3.0)
98
+ yard (0.9.45)
97
99
 
98
100
  PLATFORMS
99
101
  arm64-darwin-22
@@ -111,12 +113,13 @@ DEPENDENCIES
111
113
  rake (~> 13.2)
112
114
  random-port!
113
115
  rubocop (~> 1.75)
116
+ rubocop-elegant (~> 0.5)
114
117
  rubocop-minitest (~> 0.38)
115
118
  rubocop-performance (~> 1.25)
116
119
  rubocop-rake (~> 0.7)
117
120
  rubocop-rspec (~> 3.7)
118
- simplecov (~> 0.22)
119
- simplecov-cobertura (~> 3.0)
121
+ simplecov (~> 1.0)
122
+ simplecov-cobertura (~> 4.0)
120
123
  threads (~> 0.4)
121
124
  yard (~> 0.9)
122
125
 
data/README.md CHANGED
@@ -51,7 +51,7 @@ RandomPort::Pool::SINGLETON.acquire do |port|
51
51
  end
52
52
  ```
53
53
 
54
- Or use shortened version, all methods called in `RandomPort`
54
+ Or use the shortened version; all methods called on `RandomPort`
55
55
  are delegated to `Pool::SINGLETON`:
56
56
 
57
57
  ```ruby
@@ -61,8 +61,8 @@ end
61
61
  ```
62
62
 
63
63
  The pool is thread-safe by default.
64
- You can configure it to be not-thread-safe,
65
- using optional `sync` argument of the constructor.
64
+ You can configure it to be non-thread-safe,
65
+ using the optional `sync` argument of the constructor.
66
66
 
67
67
  ## How to contribute
68
68
 
data/Rakefile CHANGED
@@ -5,9 +5,9 @@
5
5
 
6
6
  require 'os'
7
7
  require 'qbash'
8
- require 'rubygems'
9
8
  require 'rake'
10
9
  require 'rake/clean'
10
+ require 'rubygems'
11
11
  require 'shellwords'
12
12
 
13
13
  CLEAN << 'coverage'
@@ -31,7 +31,6 @@ class RandomPort::Pool
31
31
  # Raised when a port cannot be acquired within the timeout period.
32
32
  class Timeout < StandardError; end
33
33
 
34
- # @return [Integer] The maximum number of ports that can be acquired from this pool
35
34
  attr_reader :limit
36
35
 
37
36
  # Constructor.
@@ -43,10 +42,10 @@ class RandomPort::Pool
43
42
  @sync = sync
44
43
  @monitor = Monitor.new
45
44
  @limit = limit
45
+ @start = start
46
46
  @next = start
47
47
  end
48
48
 
49
- # Application-wide singleton pool of ports.
50
49
  SINGLETON = RandomPort::Pool.new
51
50
 
52
51
  # Returns the number of ports currently acquired from the pool.
@@ -74,15 +73,23 @@ class RandomPort::Pool
74
73
  # @return [Integer|Array<Integer>] The acquired port(s) if no block given
75
74
  # @raise [Timeout] If ports cannot be acquired within the timeout period
76
75
  def acquire(total = 1, timeout: 4)
76
+ unless total.is_a?(Integer) && total.positive?
77
+ raise(
78
+ ArgumentError,
79
+ 'The number of ports to acquire must be a positive integer, ' \
80
+ "but #{total.inspect} was provided"
81
+ )
82
+ end
77
83
  start = Time.now
78
84
  attempt = 0
79
85
  loop do
80
86
  if Time.now > start + timeout
81
- raise \
87
+ raise(
82
88
  Timeout,
83
89
  "Can't find a place in the pool of #{@limit} ports " \
84
90
  "(#{@ports.size} already occupied) " \
85
91
  "for #{total} port(s), after #{attempt} attempts in #{start.ago}"
92
+ )
86
93
  end
87
94
  attempt += 1
88
95
  opts = safe { group(total) }
@@ -91,12 +98,12 @@ class RandomPort::Pool
91
98
  else
92
99
  @next = opts.max + 1
93
100
  end
94
- @next = 0 if @next > 65_535
101
+ @next = @start if @next > 65_535
95
102
  next if opts.nil?
96
103
  opts = opts[0] if total == 1
97
104
  return opts unless block_given?
98
105
  begin
99
- return yield opts
106
+ return yield(opts)
100
107
  ensure
101
108
  release(opts)
102
109
  end
@@ -122,19 +129,17 @@ class RandomPort::Pool
122
129
  # @param [Integer] total The number of ports to acquire
123
130
  # @return [Array<Integer>|nil] An array of port numbers if successful, nil otherwise
124
131
  def group(total)
125
- return nil if @ports.count + total > @limit
132
+ return if @ports.count + total > @limit
126
133
  opts = Array.new(total, 0)
127
134
  begin
128
135
  (0..(total - 1)).each do |i|
129
- port = i.zero? ? @next : opts[i - 1] + 1
130
- opts[i] = take(port)
136
+ opts[i] = take((i.zero? ? @next : opts[i - 1] + 1))
131
137
  end
132
138
  rescue Errno::EADDRINUSE, SocketError
133
- return nil
139
+ return
134
140
  end
135
- return nil if opts.any? { |p| @ports.include?(p) }
136
- d = total * (total - 1) / 2
137
- return nil unless opts.sum - (total * opts.min) == d
141
+ return if opts.intersect?(@ports)
142
+ return unless opts.sum - (total * opts.min) == (total * (total - 1) / 2)
138
143
  @ports += opts
139
144
  opts
140
145
  end
data/random-port.gemspec CHANGED
@@ -5,10 +5,10 @@
5
5
 
6
6
  require 'English'
7
7
  Gem::Specification.new do |s|
8
- s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
8
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?(:required_rubygems_version=)
9
9
  s.required_ruby_version = '>=3.3'
10
10
  s.name = 'random-port'
11
- s.version = '0.8.2'
11
+ s.version = '0.8.3'
12
12
  s.license = 'MIT'
13
13
  s.summary = 'Random TCP port'
14
14
  s.description = 'Reserves a random TCP port'
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.files = `git ls-files | grep -v -E '^(test/|\\.|renovate)'`.split($RS)
19
19
  s.rdoc_options = ['--charset=UTF-8']
20
20
  s.extra_rdoc_files = ['README.md']
21
- s.add_dependency 'tago', '~>0.0'
21
+ s.add_dependency('tago', '~>0.0')
22
22
  s.metadata['rubygems_mfa_required'] = 'true'
23
23
  end
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.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko