random-port 0.1.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 622ec730981172b9ece844b01891f776ba10eec0
4
- data.tar.gz: 892603f1db2a0d525272c753479cf554c0b08022
3
+ metadata.gz: 9a3960a47566f1625908e17fe12c37553c20e431
4
+ data.tar.gz: a7533bbd55eb0e11ba25e9477634889eeca20168
5
5
  SHA512:
6
- metadata.gz: 6b503dae8d4b98ecdc3695d26a6e40394cfe42f199593bad55224843baf1da304ec8cd09b7636bf84148dba0947813f972cb255b832c6bf1b59736b9300ba487
7
- data.tar.gz: b2c5d5abdcb363f313023936bb36d02133bfedbde9b710ebbb7da935c5f9c0c8f8611625be064d8e96d7352e6f1fd211202c6eab9c93db45b62926517eadb1c8
6
+ metadata.gz: 78f107699b64c07926eb503c8a3253aa8756adcc5436abb76e3661b78251f9a50ce3fd21c39e73d299000e68679132c173bdca575a5b7d2ca0561fddaff3984a
7
+ data.tar.gz: 669969cd33c4523be191195e983245acce4e24ba25b912ba577d4c4708812f10ebb69a75e7e70c38a1af346e35c059c3b09b3c8c9f23d8b622262b5a1f53c271
data/README.md CHANGED
@@ -38,6 +38,14 @@ port = pool.acquire
38
38
  pool.release(port)
39
39
  ```
40
40
 
41
+ You can also use a pre-defined `Pool::SINGLETON` singleton:
42
+
43
+ ```ruby
44
+ RandomPort::Pool::SINGLETON.acquire do |port|
45
+ # Use it here...
46
+ end
47
+ ```
48
+
41
49
  The pool is thread-safe.
42
50
 
43
51
  # License
@@ -35,6 +35,9 @@ module RandomPort
35
35
  @mutex = Mutex.new
36
36
  end
37
37
 
38
+ # Application wide pool of ports
39
+ SINGLETON = Pool.new
40
+
38
41
  def acquire
39
42
  @mutex.synchronize do
40
43
  loop do
@@ -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.1.0'
34
+ s.version = '0.2.0'
35
35
  s.license = 'MIT'
36
36
  s.summary = 'Random TCP port'
37
37
  s.description = 'Reserves a random TCP port'
@@ -45,5 +45,12 @@ module RandomPort
45
45
  assert(port.positive?)
46
46
  end
47
47
  end
48
+
49
+ def test_acquires_and_releases_from_singleton
50
+ Pool::SINGLETON.acquire do |port|
51
+ assert(!port.nil?)
52
+ assert(port.positive?)
53
+ end
54
+ end
48
55
  end
49
56
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko