protoplasm-blocking-client 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,19 @@ module Protoplasm
10
10
  cls
11
11
  end
12
12
 
13
+ def close
14
+ _socket.close if _socket && !_socket.closed?
15
+ end
16
+
17
+ def self.client(*args)
18
+ client = new(*args)
19
+ begin
20
+ yield client
21
+ ensure
22
+ client.close
23
+ end
24
+ end
25
+
13
26
  private
14
27
  def host_port
15
28
  raise "Must be implemented by the client class"
@@ -24,7 +37,7 @@ module Protoplasm
24
37
  s.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
25
38
  s
26
39
  end
27
- yield @socket
40
+ yield @socket if block_given?
28
41
  rescue Errno::EPIPE, Errno::ECONNRESET
29
42
  count += 1
30
43
  if count > 3
@@ -1,3 +1,3 @@
1
1
  module Protoplasm
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -43,6 +43,22 @@ describe "Protoplasm test server" do
43
43
  end
44
44
  end
45
45
 
46
+ it "should allow a self closing client" do
47
+ with_proto_server(ProtoplasmTest::EMServer) do |port|
48
+ ProtoplasmTest::Client.client('127.0.0.1', port) do |client|
49
+ client.ping
50
+ assert_equal "LOWER", client.upcase('lower')
51
+ assert_equal "UPPER", client.upcase('upper')
52
+ nums = []
53
+ client.evens(10) do |resp|
54
+ nums << resp
55
+ end
56
+ assert_equal [2, 4, 6, 8], nums
57
+ client.ping
58
+ assert_equal "LOWER", client.upcase('lower')
59
+ end
60
+ end
61
+ end
46
62
  it "should do constant lookups" do
47
63
  assert_equal :PING, ProtoplasmTest::Types::Command::Type.lookup(1)
48
64
  assert_equal :UPCASE, ProtoplasmTest::Types::Command::Type.lookup(2)
metadata CHANGED
@@ -1,78 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: protoplasm-blocking-client
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 5
10
- version: 0.1.5
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Josh Hull
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-02-01 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: beefcake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70175495996740 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 29
29
- segments:
30
- - 0
31
- - 3
32
- - 7
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.3.7
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rake
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70175495996740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70175496015700 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
48
33
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: minitest
52
34
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70175496015700
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70175496014780 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
40
+ requirements:
56
41
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 21
59
- segments:
60
- - 2
61
- - 6
62
- - 1
42
+ - !ruby/object:Gem::Version
63
43
  version: 2.6.1
64
44
  type: :development
65
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *70175496014780
66
47
  description: A blocking client for a Protoplasm server.
67
- email:
48
+ email:
68
49
  - joshbuddy@gmail.com
69
50
  executables: []
70
-
71
51
  extensions: []
72
-
73
52
  extra_rdoc_files: []
74
-
75
- files:
53
+ files:
76
54
  - .gitignore
77
55
  - Gemfile
78
56
  - README.md
@@ -88,38 +66,29 @@ files:
88
66
  - test/test_helper.rb
89
67
  homepage: https://github.com/bazaarlabs/protoplasm
90
68
  licenses: []
91
-
92
69
  post_install_message:
93
70
  rdoc_options: []
94
-
95
- require_paths:
71
+ require_paths:
96
72
  - lib
97
- required_ruby_version: !ruby/object:Gem::Requirement
73
+ required_ruby_version: !ruby/object:Gem::Requirement
98
74
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
106
- required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
80
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
- version: "0"
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
115
85
  requirements: []
116
-
117
86
  rubyforge_project: protoplasm-blocking-client
118
87
  rubygems_version: 1.8.15
119
88
  signing_key:
120
89
  specification_version: 3
121
90
  summary: A blocking client for a Protoplasm server
122
- test_files:
91
+ test_files:
123
92
  - test/protoplasm_test.rb
124
93
  - test/test_helper.rb
125
94
  has_rdoc: