nest 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +1 -1
  2. data/nest.gemspec +2 -2
  3. data/test/commands.rb +72 -0
  4. metadata +3 -2
@@ -47,7 +47,7 @@ And you can use any object as a key, not only strings:
47
47
  => "foo:42"
48
48
 
49
49
  In a more realistic tone, lets assume you are working with Redis and
50
- dealing with events:
50
+ dealing with users:
51
51
 
52
52
  >> event = Nest.new("event")
53
53
  => "event"
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "nest"
3
- s.version = "0.0.0"
3
+ s.version = "0.0.1"
4
4
  s.summary = "Generate nested namespaced keys for key-value databases."
5
5
  s.description = "It is a design pattern in key-value databases to use the key to simulate structure, and Nest can take care of that."
6
6
  s.authors = ["Michel Martens"]
7
7
  s.email = ["michel@soveran.com"]
8
8
  s.homepage = "http://github.com/soveran/nest"
9
- s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/nest.rb", "nest.gemspec", "test/nest_test.rb", "test/test_helper.rb"]
9
+ s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/nest.rb", "nest.gemspec", "test/commands.rb", "test/nest_test.rb", "test/test_helper.rb"]
10
10
  end
@@ -0,0 +1,72 @@
1
+ require "open3"
2
+ require "socket"
3
+
4
+ module Test::Commands
5
+ def sh(cmd)
6
+ out, err = nil
7
+
8
+ Open3.popen3(cmd) do |_in, _out, _err|
9
+ out = _out.read
10
+ err = _err.read
11
+ end
12
+
13
+ [out, err]
14
+ end
15
+
16
+ # Runs a command in the background, silencing all output.
17
+ # For debugging purposes, set the environment variable VERBOSE.
18
+ def sh_bg(cmd)
19
+ if ENV["VERBOSE"]
20
+ streams_to_silence = []
21
+ else
22
+ streams_to_silence = [$stdout, $stderr]
23
+ cmd = "#{cmd} 2>&1>/dev/null"
24
+ end
25
+
26
+ silence_stream(*streams_to_silence) do
27
+ (pid = fork) ? Process.detach(pid) : exec(cmd)
28
+ end
29
+ end
30
+
31
+ def listening?(host, port)
32
+ begin
33
+ socket = TCPSocket.new(host, port)
34
+ socket.close unless socket.nil?
35
+ true
36
+ rescue Errno::ECONNREFUSED,
37
+ Errno::EBADF, # Windows
38
+ Errno::EADDRNOTAVAIL # Windows
39
+ false
40
+ end
41
+ end
42
+
43
+ def wait_for_service(host, port, timeout = 3)
44
+ start_time = Time.now
45
+
46
+ until listening?(host, port)
47
+ if timeout && (Time.now > (start_time + timeout))
48
+ raise SocketError.new("Socket #{host}:#{port} did not open within #{timeout} seconds")
49
+ end
50
+ end
51
+
52
+ true
53
+ end
54
+
55
+ def suspects(port)
56
+ list = sh("lsof -i :#{port}").first.split("\n")[1..-1] || []
57
+ list.map {|s| s[/^.+? (\d+)/, 1] }
58
+ end
59
+
60
+ def silence_stream(*streams) #:yeild:
61
+ on_hold = streams.collect{ |stream| stream.dup }
62
+ streams.each do |stream|
63
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
64
+ stream.sync = true
65
+ end
66
+ yield
67
+ ensure
68
+ streams.each_with_index do |stream, i|
69
+ stream.reopen(on_hold[i])
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michel Martens
@@ -33,6 +33,7 @@ files:
33
33
  - Rakefile
34
34
  - lib/nest.rb
35
35
  - nest.gemspec
36
+ - test/commands.rb
36
37
  - test/nest_test.rb
37
38
  - test/test_helper.rb
38
39
  has_rdoc: true