ohm 0.0.36 → 0.0.37
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohm.rb +5 -4
- data/lib/ohm/collection.rb +2 -2
- data/test/model_test.rb +8 -3
- metadata +8 -3
data/lib/ohm.rb
CHANGED
@@ -9,7 +9,7 @@ require File.join(File.dirname(__FILE__), "ohm", "key")
|
|
9
9
|
require File.join(File.dirname(__FILE__), "ohm", "collection")
|
10
10
|
|
11
11
|
module Ohm
|
12
|
-
VERSION = "0.0.
|
12
|
+
VERSION = "0.0.37"
|
13
13
|
|
14
14
|
# Provides access to the Redis database. This is shared accross all models and instances.
|
15
15
|
def redis
|
@@ -290,7 +290,7 @@ module Ohm
|
|
290
290
|
# @overload assert_unique [:street, :city]
|
291
291
|
# Validates that the :street and :city pair is unique.
|
292
292
|
def assert_unique(attrs)
|
293
|
-
result = db.sinter(*Array(attrs).map { |att| index_key_for(att, send(att)) })
|
293
|
+
result = db.sinter(*Array(attrs).map { |att| index_key_for(att, send(att)) }) || []
|
294
294
|
assert result.empty? || !new? && result.include?(id.to_s), [attrs, :not_unique]
|
295
295
|
end
|
296
296
|
end
|
@@ -786,10 +786,11 @@ module Ohm
|
|
786
786
|
end
|
787
787
|
|
788
788
|
def delete_from_indices
|
789
|
-
db.smembers(key(:_indices)).each do |index|
|
789
|
+
(db.smembers(key(:_indices)) || []).each do |index|
|
790
790
|
db.srem(index, id)
|
791
|
-
db.srem(key(:_indices), index)
|
792
791
|
end
|
792
|
+
|
793
|
+
db.del(key(:_indices))
|
793
794
|
end
|
794
795
|
|
795
796
|
def read_local(att)
|
data/lib/ohm/collection.rb
CHANGED
@@ -124,7 +124,7 @@ module Ohm
|
|
124
124
|
|
125
125
|
# @return [Array] Elements of the list.
|
126
126
|
def all
|
127
|
-
db.lrange(key, 0, -1)
|
127
|
+
db.lrange(key, 0, -1) || []
|
128
128
|
end
|
129
129
|
|
130
130
|
# @return [Integer] Returns the number of elements in the list.
|
@@ -171,7 +171,7 @@ module Ohm
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def all
|
174
|
-
db.smembers(key)
|
174
|
+
db.smembers(key) || []
|
175
175
|
end
|
176
176
|
|
177
177
|
# @return [Integer] Returns the number of elements in the set.
|
data/test/model_test.rb
CHANGED
@@ -277,8 +277,8 @@ class TestRedis < Test::Unit::TestCase
|
|
277
277
|
|
278
278
|
assert_nil Ohm.redis.get(ModelToBeDeleted.key(id))
|
279
279
|
assert_nil Ohm.redis.get(ModelToBeDeleted.key(id, :name))
|
280
|
-
|
281
|
-
|
280
|
+
assert !Ohm.redis.exists(ModelToBeDeleted.key(id, :foos))
|
281
|
+
assert !Ohm.redis.exists(ModelToBeDeleted.key(id, :bars))
|
282
282
|
|
283
283
|
assert ModelToBeDeleted.all.empty?
|
284
284
|
end
|
@@ -297,7 +297,12 @@ class TestRedis < Test::Unit::TestCase
|
|
297
297
|
|
298
298
|
Foo[1].delete
|
299
299
|
|
300
|
-
|
300
|
+
keys = Ohm.redis.keys("*")
|
301
|
+
|
302
|
+
assert !keys.include?("Foo:1:_indices")
|
303
|
+
assert !keys.include?("Foo:1:name")
|
304
|
+
|
305
|
+
assert_equal "1", Ohm.redis.get("Foo:id")
|
301
306
|
end
|
302
307
|
end
|
303
308
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 85
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 37
|
10
|
+
version: 0.0.37
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Michel Martens
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-07-
|
19
|
+
date: 2010-07-07 00:00:00 -03:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -26,6 +27,7 @@ dependencies:
|
|
26
27
|
requirements:
|
27
28
|
- - ">="
|
28
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 31
|
29
31
|
segments:
|
30
32
|
- 1
|
31
33
|
- 0
|
@@ -41,6 +43,7 @@ dependencies:
|
|
41
43
|
requirements:
|
42
44
|
- - ~>
|
43
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 9
|
44
47
|
segments:
|
45
48
|
- 0
|
46
49
|
- 1
|
@@ -92,6 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
95
|
requirements:
|
93
96
|
- - ">="
|
94
97
|
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
95
99
|
segments:
|
96
100
|
- 0
|
97
101
|
version: "0"
|
@@ -100,6 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
104
|
requirements:
|
101
105
|
- - ">="
|
102
106
|
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
103
108
|
segments:
|
104
109
|
- 0
|
105
110
|
version: "0"
|