ohm 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohm.rb +2 -5
- data/lib/ohm/version.rb +1 -1
- data/test/connection_test.rb +56 -0
- metadata +9 -9
data/lib/ohm.rb
CHANGED
@@ -1715,6 +1715,7 @@ module Ohm
|
|
1715
1715
|
#
|
1716
1716
|
# @see file:README.html#connecting Ohm.connect options documentation.
|
1717
1717
|
def self.connect(options = {})
|
1718
|
+
Ohm.threaded[self] = nil
|
1718
1719
|
@options = options
|
1719
1720
|
end
|
1720
1721
|
|
@@ -1805,11 +1806,7 @@ module Ohm
|
|
1805
1806
|
def self.db
|
1806
1807
|
return Ohm.redis unless defined?(@options)
|
1807
1808
|
|
1808
|
-
Redis.connect(@options)
|
1809
|
-
end
|
1810
|
-
|
1811
|
-
def self.db=(connection)
|
1812
|
-
Ohm.threaded[self] = connection
|
1809
|
+
Ohm.threaded[self] ||= Redis.connect(@options)
|
1813
1810
|
end
|
1814
1811
|
|
1815
1812
|
# Allows you to do key manipulations scoped solely to your class.
|
data/lib/ohm/version.rb
CHANGED
data/test/connection_test.rb
CHANGED
@@ -43,3 +43,59 @@ test "supports connecting by URL" do
|
|
43
43
|
assert Errno::ECONNREFUSED == e.class
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
test "Model.db is the same as Ohm.redis by default" do
|
48
|
+
class U < Ohm::Model
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_equal U.db.object_id, Ohm.redis.object_id
|
52
|
+
end
|
53
|
+
|
54
|
+
test "provides a unique Model.db connection in one thread" do
|
55
|
+
class U < Ohm::Model
|
56
|
+
end
|
57
|
+
|
58
|
+
U.connect(db: 9876)
|
59
|
+
|
60
|
+
r1 = U.db
|
61
|
+
r2 = U.db
|
62
|
+
|
63
|
+
assert_equal r1.object_id, r2.object_id
|
64
|
+
end
|
65
|
+
|
66
|
+
test "provides distinct Model.db connections per thread" do
|
67
|
+
class U < Ohm::Model
|
68
|
+
end
|
69
|
+
|
70
|
+
U.connect(db: 9876)
|
71
|
+
|
72
|
+
r1 = nil
|
73
|
+
r2 = nil
|
74
|
+
|
75
|
+
Thread.new { r1 = U.db }.join
|
76
|
+
Thread.new { r2 = U.db }.join
|
77
|
+
|
78
|
+
assert r1.object_id != r2.object_id
|
79
|
+
end
|
80
|
+
|
81
|
+
test "busts threaded cache when doing Model.connect" do
|
82
|
+
class U < Ohm::Model
|
83
|
+
end
|
84
|
+
|
85
|
+
U.connect(db: 9876)
|
86
|
+
r1 = U.db
|
87
|
+
|
88
|
+
U.connect(db: 9876)
|
89
|
+
r2 = U.db
|
90
|
+
|
91
|
+
assert r1.object_id != r2.object_id
|
92
|
+
end
|
93
|
+
|
94
|
+
test "disallows the non-thread safe writing of Model.db" do
|
95
|
+
class U < Ohm::Model
|
96
|
+
end
|
97
|
+
|
98
|
+
assert_raise NoMethodError do
|
99
|
+
U.db = Redis.connect
|
100
|
+
end
|
101
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nest
|
17
|
-
requirement: &
|
17
|
+
requirement: &70360766634860 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '1.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70360766634860
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: cutest
|
28
|
-
requirement: &
|
28
|
+
requirement: &70360766633980 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70360766633980
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: batch
|
39
|
-
requirement: &
|
39
|
+
requirement: &70360766633360 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: 0.0.1
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70360766633360
|
48
48
|
description: Ohm is a library that allows to store an object in Redis, a persistent
|
49
49
|
key-value database. It includes an extensible list of validations and has very good
|
50
50
|
performance.
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project: ohm
|
103
|
-
rubygems_version: 1.8.
|
103
|
+
rubygems_version: 1.8.11
|
104
104
|
signing_key:
|
105
105
|
specification_version: 3
|
106
106
|
summary: Object-hash mapping library for Redis.
|