alloc8 0.0.2 → 0.0.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.
- data/lib/alloc8.rb +6 -3
- data/lib/alloc8/version.rb +1 -1
- data/spec/alloc8_spec.rb +10 -1
- metadata +4 -4
data/lib/alloc8.rb
CHANGED
@@ -60,9 +60,12 @@ module Alloc8
|
|
60
60
|
# block to allocate a resource
|
61
61
|
def self.with_resource(klass, host, port, db=nil)
|
62
62
|
a = Alloc8::Tor.new host, port, db
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
begin
|
64
|
+
res = a.acquire(klass)
|
65
|
+
yield res
|
66
|
+
ensure
|
67
|
+
a.return(klass, res)
|
68
|
+
end
|
66
69
|
end
|
67
70
|
|
68
71
|
private
|
data/lib/alloc8/version.rb
CHANGED
data/spec/alloc8_spec.rb
CHANGED
@@ -52,10 +52,19 @@ describe Alloc8 do
|
|
52
52
|
lambda { @allocator.return(KIND, "foo") }.should raise_error
|
53
53
|
end
|
54
54
|
|
55
|
-
it "can acquire with a block" do
|
55
|
+
it "can acquire with a block, and returns correctly" do
|
56
56
|
Alloc8::Tor.with_resource(KIND, HOST, PORT) do |res|
|
57
57
|
res.should == "a"
|
58
|
+
@allocator.available(KIND).should eq([])
|
58
59
|
end
|
60
|
+
@allocator.list(KIND).should eq(["a"])
|
61
|
+
@allocator.available(KIND).should eq(["a"])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can acquire with a block, and handle an exception" do
|
65
|
+
lambda { Alloc8::Tor.with_resource(KIND, HOST, PORT) { raise Exception.new("test") } }.should raise_error
|
66
|
+
@allocator.list(KIND).should eq(["a"])
|
67
|
+
@allocator.available(KIND).should eq(["a"])
|
59
68
|
end
|
60
69
|
|
61
70
|
it "can't acquire a second resource" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alloc8
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ariel Salomon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-23 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|