random-port 0.3.1 → 0.3.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: 8d89270eaf87254ef245e9a207758052081e2d50b530d3d0f893bda91e35406d
4
- data.tar.gz: 61261be32c1b20a47306df4773ecd527e86efc20d8cb734d127cdeb6fa92a8cf
3
+ metadata.gz: 1cd0eda08b292d0482e433b081e984bde31aed33b758faf81815d7e6bebab95a
4
+ data.tar.gz: cec78b2727717531359e826f1e650981dfc6c0bc37fcb914ce503424824c66ae
5
5
  SHA512:
6
- metadata.gz: f6c36601ddfe67c1cd4d427ec3d7afd9a2ffaa82f698e13077707cd904b2241ab6fd73ac16bb5e5d2547f239df08a18340d4bf6253fd24514dd73556ca894a84
7
- data.tar.gz: f46462e3038d131436fdbd82cdd3e65ae413c005f4e30a6652bda1a09a1560018fcb1c94f6fbd4ff8830bdcea468c76833f41666dd04ccfe18123bceee416d95
6
+ metadata.gz: ca08ad8ead3c38bcc22431d5526bad4142ecfdcc3341af242a162872d3caa33261bbe4618d6c350f20b18e6401a32e69ab5da2af2e4631957a30ef679dd26cac
7
+ data.tar.gz: d349dce4ab4e7171b15526f8b731d95874f3311eebbc247970210e5581d694aee1587e12c5044e52f08e1785dece7441b3ba4263bd7c10cc4983f5efa22b44a9
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ Gemfile.lock
3
3
  .bundle/
4
4
  .DS_Store
5
5
  rdoc/
6
+ coverage/
data/.rultor.yml CHANGED
@@ -3,10 +3,10 @@ assets:
3
3
  install: |-
4
4
  export GEM_HOME=~/.ruby
5
5
  export GEM_PATH=$GEM_HOME:$GEM_PATH
6
+ bundle install
6
7
  release:
7
8
  script: |-
8
- bundle install
9
- rake
9
+ bundle exec rake
10
10
  rm -rf *.gem
11
11
  sed -i "s/0\.0\.0/${tag}/g" random-port.gemspec
12
12
  git add random-port.gemspec
@@ -14,10 +14,10 @@ release:
14
14
  gem build random-port.gemspec
15
15
  chmod 0600 ../rubygems.yml
16
16
  gem push *.gem --config-file ../rubygems.yml
17
- commanders:
18
- - yegor256
19
- architect:
20
- - yegor256
21
17
  merge:
22
- commanders: []
23
- deploy: {}
18
+ script: |-
19
+ bundle exec rake
20
+ deploy:
21
+ script: |-
22
+ echo Nothing to deploy
23
+ exit -1
data/.travis.yml CHANGED
@@ -1,12 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.3
3
+ - 2.6.0
4
+ cache: bundler
4
5
  branches:
5
6
  only:
6
7
  - master
7
8
  install:
8
- - bundle install
9
+ - travis_retry bundle update
9
10
  script:
10
- - set -e
11
- - rake
12
-
11
+ - bundle exec rake
12
+ after_success:
13
+ - "bash <(curl -s https://codecov.io/bash)"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2019 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
@@ -5,6 +5,10 @@
5
5
  [![Gem Version](https://badge.fury.io/rb/random-port.svg)](http://badge.fury.io/rb/random-port)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/349b8c31884d3b34d926/maintainability)](https://codeclimate.com/github/yegor256/random-port/maintainability)
7
7
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/random-port/master/frames)
8
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/random-port/blob/master/LICENSE.txt)
9
+
10
+ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/random-port.svg)](https://codecov.io/github/yegor256/random-port?branch=master)
11
+ [![Hits-of-Code](https://hitsofcode.com/github/yegor256/random-port)](https://hitsofcode.com/view/github/random-port/mailanes)
8
12
 
9
13
  It's a simple Ruby gem to get a random TCP port.
10
14
 
@@ -51,7 +55,7 @@ The pool is thread-safe by default.
51
55
  You can configure it to be
52
56
  not-thread-safe, using optional `sync` argument of the constructor.
53
57
 
54
- # How to contribute
58
+ ## How to contribute
55
59
 
56
60
  Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
57
61
  Make sure you build is green before you contribute
@@ -60,31 +64,7 @@ your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2
60
64
 
61
65
  ```
62
66
  $ bundle update
63
- $ rake
67
+ $ bundle exec rake
64
68
  ```
65
69
 
66
70
  If it's clean and you don't see any error messages, submit your pull request.
67
-
68
- # License
69
-
70
- (The MIT License)
71
-
72
- Copyright (c) 2018 Yegor Bugayenko
73
-
74
- Permission is hereby granted, free of charge, to any person obtaining a copy
75
- of this software and associated documentation files (the 'Software'), to deal
76
- in the Software without restriction, including without limitation the rights
77
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
78
- copies of the Software, and to permit persons to whom the Software is
79
- furnished to do so, subject to the following conditions:
80
-
81
- The above copyright notice and this permission notice shall be included in all
82
- copies or substantial portions of the Software.
83
-
84
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
85
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
86
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
87
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
88
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
89
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
90
- SOFTWARE.
@@ -51,6 +51,16 @@ module RandomPort
51
51
  # Application wide pool of ports
52
52
  SINGLETON = Pool.new
53
53
 
54
+ # How many ports acquired now?
55
+ def count
56
+ @ports.count
57
+ end
58
+
59
+ # Is it empty?
60
+ def empty?
61
+ @ports.empty?
62
+ end
63
+
54
64
  # Acquire a new random TCP port.
55
65
  def acquire
56
66
  loop do
@@ -60,9 +70,11 @@ module RandomPort
60
70
  next if @ports.include?(port)
61
71
  safe { @ports << port }
62
72
  return port unless block_given?
63
- yield port
64
- safe { @ports.delete(port) }
65
- break
73
+ begin
74
+ return yield port
75
+ ensure
76
+ safe { @ports.delete(port) }
77
+ end
66
78
  end
67
79
  end
68
80
 
data/random-port.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.rubygems_version = '2.3.3'
32
32
  s.required_ruby_version = '>=2.3'
33
33
  s.name = 'random-port'
34
- s.version = '0.3.1'
34
+ s.version = '0.3.2'
35
35
  s.license = 'MIT'
36
36
  s.summary = 'Random TCP port'
37
37
  s.description = 'Reserves a random TCP port'
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
42
42
  s.test_files = s.files.grep(%r{^(test)/})
43
43
  s.rdoc_options = ['--charset=UTF-8']
44
44
  s.extra_rdoc_files = ['README.md']
45
+ s.add_development_dependency 'codecov', '0.1.10'
45
46
  s.add_development_dependency 'minitest', '5.11.3'
46
47
  s.add_development_dependency 'rake', '12.3.1'
47
48
  s.add_development_dependency 'rdoc', '4.3.0'
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018-2019 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 NONINFINGEMENT. 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.
22
+
23
+ STDOUT.sync = true
24
+
25
+ require 'simplecov'
26
+ SimpleCov.start
27
+ if ENV['CI'] == 'true'
28
+ require 'codecov'
29
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
30
+ end
31
+
32
+ require 'minitest/autorun'
data/test/test_pool.rb CHANGED
@@ -40,10 +40,22 @@ module RandomPort
40
40
  end
41
41
 
42
42
  def test_acquires_and_releases_in_block
43
- Pool.new.acquire do |port|
43
+ result = Pool.new.acquire do |port|
44
44
  assert(!port.nil?)
45
45
  assert(port.positive?)
46
+ 123
46
47
  end
48
+ assert_equal(123, result)
49
+ end
50
+
51
+ def test_acquires_and_releases_safely
52
+ pool = Pool.new
53
+ assert_raises do
54
+ pool.acquire do
55
+ raise 'Itended'
56
+ end
57
+ end
58
+ assert(pool.count.zero?)
47
59
  end
48
60
 
49
61
  def test_acquires_and_releases_from_singleton
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random-port
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-12 00:00:00.000000000 Z
11
+ date: 2019-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: codecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.10
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.10
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,11 +108,13 @@ files:
94
108
  - ".rultor.yml"
95
109
  - ".travis.yml"
96
110
  - Gemfile
111
+ - LICENSE.txt
97
112
  - README.md
98
113
  - Rakefile
99
114
  - lib/random-port.rb
100
115
  - lib/random-port/pool.rb
101
116
  - random-port.gemspec
117
+ - test/test__helper.rb
102
118
  - test/test_pool.rb
103
119
  homepage: http://github.com/yegor256/random-port
104
120
  licenses:
@@ -120,10 +136,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
136
  - !ruby/object:Gem::Version
121
137
  version: '0'
122
138
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.7.6
139
+ rubygems_version: 3.0.1
125
140
  signing_key:
126
141
  specification_version: 2
127
142
  summary: Random TCP port
128
143
  test_files:
144
+ - test/test__helper.rb
129
145
  - test/test_pool.rb