ohm 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +9 -3
- data/lib/ohm.rb +3 -3
- data/lib/ohm/redis.rb +2 -3
- data/test/benchmarks.rb +0 -17
- data/test/db/redis.pid +1 -1
- data/test/indices_test.rb +2 -2
- data/test/validations_test.rb +2 -2
- metadata +14 -9
data/README.markdown
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Ohm
|
2
|
-
|
2
|
+
===
|
3
3
|
|
4
4
|
Object-hash mapping library for Redis.
|
5
5
|
|
@@ -16,11 +16,12 @@ Usage
|
|
16
16
|
|
17
17
|
require 'ohm'
|
18
18
|
|
19
|
-
|
19
|
+
Ohm.connect
|
20
20
|
|
21
21
|
class Event < Ohm::Model
|
22
22
|
attribute :name
|
23
23
|
set :participants
|
24
|
+
list :comments
|
24
25
|
|
25
26
|
def validate
|
26
27
|
assert_present :name
|
@@ -30,6 +31,11 @@ Usage
|
|
30
31
|
event = Event.create(:name => "Ruby Tuesday")
|
31
32
|
event.participants << "Michel Martens"
|
32
33
|
event.participants << "Damian Janowski"
|
34
|
+
event.participants #=> ["Damian Janowski", "Michel Martens"]
|
35
|
+
|
36
|
+
event.comments << "Very interesting event!"
|
37
|
+
event.comments << "Agree"
|
38
|
+
event.comments #=> ["Very interesting event!", "Agree"]
|
33
39
|
|
34
40
|
another_event = Event.new
|
35
41
|
another_event.valid? #=> false
|
@@ -40,7 +46,7 @@ Usage
|
|
40
46
|
another_event.errors #=> [[:name, :empty]]
|
41
47
|
|
42
48
|
another_event.name = "Ruby Lunch"
|
43
|
-
another_event.
|
49
|
+
another_event.create #=> true
|
44
50
|
|
45
51
|
Installation
|
46
52
|
------------
|
data/lib/ohm.rb
CHANGED
@@ -65,8 +65,8 @@ module Ohm
|
|
65
65
|
include Ohm::Validations
|
66
66
|
|
67
67
|
def assert_unique(attrs)
|
68
|
-
index_key = index_key_for(attrs, read_locals(attrs))
|
69
|
-
assert(db.scard(index_key).zero? || db.sismember(index_key, id), [attrs, :not_unique])
|
68
|
+
index_key = index_key_for(Array(attrs), read_locals(Array(attrs)))
|
69
|
+
assert(db.scard(index_key).zero? || db.sismember(index_key, id), [Array(attrs), :not_unique])
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -103,7 +103,7 @@ module Ohm
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def self.index(attrs)
|
106
|
-
indices << attrs
|
106
|
+
indices << Array(attrs)
|
107
107
|
end
|
108
108
|
|
109
109
|
def self.attr_list_reader(name)
|
data/lib/ohm/redis.rb
CHANGED
@@ -151,15 +151,14 @@ module Ohm
|
|
151
151
|
call_command(argv)
|
152
152
|
end
|
153
153
|
|
154
|
-
|
155
154
|
# Wrap raw_call_command to handle reconnection on socket error. We
|
156
155
|
# try to reconnect just one time, otherwise let the error araise.
|
157
156
|
def call_command(argv)
|
158
157
|
connect unless connected?
|
159
|
-
raw_call_command(argv)
|
158
|
+
raw_call_command(argv.dup)
|
160
159
|
rescue Errno::ECONNRESET
|
161
160
|
reconnect
|
162
|
-
raw_call_command(argv)
|
161
|
+
raw_call_command(argv.dup)
|
163
162
|
end
|
164
163
|
|
165
164
|
def raw_call_command(argv)
|
data/test/benchmarks.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "bench"
|
3
3
|
require File.dirname(__FILE__) + "/../lib/ohm"
|
4
|
-
require "redis"
|
5
4
|
|
6
5
|
Ohm.connect(:port => 6381)
|
7
6
|
Ohm.flush
|
8
7
|
|
9
|
-
$r = Redis.new(:port => 6381)
|
10
|
-
|
11
8
|
class Event < Ohm::Model
|
12
9
|
attribute :name
|
13
10
|
set :attendees
|
@@ -24,10 +21,6 @@ benchmark "add to set with ohm redis" do
|
|
24
21
|
Ohm.redis.sadd("foo", 1)
|
25
22
|
end
|
26
23
|
|
27
|
-
benchmark "add to set with redis" do
|
28
|
-
$r.set_add("foo", 1)
|
29
|
-
end
|
30
|
-
|
31
24
|
benchmark "add to set with ohm" do
|
32
25
|
event.attendees << 1
|
33
26
|
end
|
@@ -41,17 +34,7 @@ benchmark "retrieve a set of two members with ohm redis" do
|
|
41
34
|
Ohm.redis.smembers("bar")
|
42
35
|
end
|
43
36
|
|
44
|
-
$r.set_add("bar", 1)
|
45
|
-
$r.set_add("bar", 2)
|
46
|
-
|
47
|
-
benchmark "retrieve a set of two members with redis" do
|
48
|
-
$r.set_add("bar", 3)
|
49
|
-
$r.set_delete("bar", 3)
|
50
|
-
$r.set_members("bar")
|
51
|
-
end
|
52
|
-
|
53
37
|
Ohm.redis.del("Event:#{event.id}:attendees")
|
54
|
-
$r.delete("Event:#{event.id}:attendees")
|
55
38
|
|
56
39
|
event.attendees << 1
|
57
40
|
event.attendees << 2
|
data/test/db/redis.pid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
6304
|
data/test/indices_test.rb
CHANGED
@@ -4,7 +4,7 @@ class IndicesTest < Test::Unit::TestCase
|
|
4
4
|
class User < Ohm::Model
|
5
5
|
attribute :email
|
6
6
|
|
7
|
-
index
|
7
|
+
index :email
|
8
8
|
end
|
9
9
|
|
10
10
|
context "A model with an indexed attribute" do
|
@@ -23,7 +23,7 @@ class IndicesTest < Test::Unit::TestCase
|
|
23
23
|
@user1.email = "baz"
|
24
24
|
@user1.save
|
25
25
|
|
26
|
-
assert_equal [], User.find(:email, "foo")
|
26
|
+
assert_equal [], User.find(:email, "foo")
|
27
27
|
assert_equal [@user1], User.find(:email, "baz")
|
28
28
|
end
|
29
29
|
|
data/test/validations_test.rb
CHANGED
@@ -5,7 +5,7 @@ class ValidationsTest < Test::Unit::TestCase
|
|
5
5
|
attribute :name
|
6
6
|
attribute :place
|
7
7
|
|
8
|
-
index
|
8
|
+
index :name
|
9
9
|
index [:name, :place]
|
10
10
|
|
11
11
|
def validate
|
@@ -48,7 +48,7 @@ class ValidationsTest < Test::Unit::TestCase
|
|
48
48
|
context "That must have a unique name" do
|
49
49
|
should "fail when the value already exists" do
|
50
50
|
def @event.validate
|
51
|
-
assert_unique
|
51
|
+
assert_unique :name
|
52
52
|
end
|
53
53
|
|
54
54
|
Event.create(:name => "foo")
|
metadata
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Michel Martens
|
7
|
+
- Michel Martens
|
8
|
+
- Damian Janowski
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date: 2009-
|
13
|
+
date: 2009-06-19 00:00:00 -03:00
|
13
14
|
default_executable:
|
14
15
|
dependencies: []
|
15
16
|
|
16
|
-
description:
|
17
|
-
email:
|
17
|
+
description: Ohm is a library that allows to store an object in Redis, a persistent key-value database. It includes an extensible list of validations and has very good performance.
|
18
|
+
email:
|
19
|
+
- michel@soveran.com
|
20
|
+
- djanowski@dimaion.com
|
18
21
|
executables: []
|
19
22
|
|
20
23
|
extensions: []
|
@@ -38,8 +41,10 @@ files:
|
|
38
41
|
- test/test.conf
|
39
42
|
- test/test_helper.rb
|
40
43
|
- test/validations_test.rb
|
41
|
-
has_rdoc:
|
44
|
+
has_rdoc: true
|
42
45
|
homepage: http://github.com/soveran/ohm
|
46
|
+
licenses: []
|
47
|
+
|
43
48
|
post_install_message:
|
44
49
|
rdoc_options: []
|
45
50
|
|
@@ -59,10 +64,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
64
|
version:
|
60
65
|
requirements: []
|
61
66
|
|
62
|
-
rubyforge_project:
|
63
|
-
rubygems_version: 1.3.
|
67
|
+
rubyforge_project: ohm
|
68
|
+
rubygems_version: 1.3.4
|
64
69
|
signing_key:
|
65
|
-
specification_version:
|
70
|
+
specification_version: 3
|
66
71
|
summary: Object-hash mapping library for Redis.
|
67
72
|
test_files: []
|
68
73
|
|