sohm 0.0.1 → 0.9.0
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.
- checksums.yaml +4 -4
- data/.travis.gemfile +9 -0
- data/.travis.yml +10 -0
- data/README.md +2 -0
- data/lib/sohm/auto_id.rb +13 -0
- data/lib/sohm/command.rb +1 -1
- data/lib/sohm/index_all.rb +18 -0
- data/lib/sohm/json.rb +1 -1
- data/lib/sohm.rb +121 -207
- data/sohm.gemspec +1 -1
- data/test/association.rb +6 -12
- data/test/command.rb +6 -6
- data/test/connection.rb +5 -5
- data/test/core.rb +4 -1
- data/test/counters.rb +2 -1
- data/test/enumerable.rb +9 -3
- data/test/filtering.rb +10 -13
- data/test/hash_key.rb +3 -1
- data/test/helper.rb +5 -3
- data/test/indices.rb +6 -36
- data/test/json.rb +8 -3
- data/test/list.rb +6 -11
- data/test/model.rb +100 -179
- data/test/set.rb +6 -2
- data/test/sohm.rb +44 -0
- data/test/to_hash.rb +5 -2
- metadata +7 -6
- data/lib/sample.rb +0 -14
- data/lib/sohm/lua/delete.lua +0 -72
- data/test/thread_safety.rb +0 -67
- data/test/uniques.rb +0 -98
data/sohm.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "sohm"
|
3
|
-
s.version = "0.0
|
3
|
+
s.version = "0.9.0"
|
4
4
|
s.summary = %{Slim ohm for twemproxy-like system}
|
5
5
|
s.description = %Q{Slim ohm is a forked ohm that works with twemproxy-like redis system, only a limited set of features in ohm is supported}
|
6
6
|
s.authors = ["Xuejie Xiao"]
|
data/test/association.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require_relative "helper"
|
2
2
|
|
3
|
-
class User <
|
3
|
+
class User < Sohm::Model
|
4
|
+
include Sohm::AutoId
|
5
|
+
|
4
6
|
collection :posts, :Post
|
5
7
|
end
|
6
8
|
|
7
|
-
class Post <
|
9
|
+
class Post < Sohm::Model
|
10
|
+
include Sohm::AutoId
|
11
|
+
|
8
12
|
reference :user, :User
|
9
13
|
end
|
10
14
|
|
@@ -21,13 +25,3 @@ test "basic shake and bake" do |u, p|
|
|
21
25
|
p = Post[p.id]
|
22
26
|
assert_equal u, p.user
|
23
27
|
end
|
24
|
-
|
25
|
-
test "memoization" do |u, p|
|
26
|
-
# This will read the user instance once.
|
27
|
-
p.user
|
28
|
-
assert_equal p.user, p.instance_variable_get(:@_memo)[:user]
|
29
|
-
|
30
|
-
# This will un-memoize the user instance
|
31
|
-
p.user = u
|
32
|
-
assert_equal nil, p.instance_variable_get(:@_memo)[:user]
|
33
|
-
end
|
data/test/command.rb
CHANGED
@@ -22,11 +22,11 @@ scope do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
test "special condition: single argument returns that arg" do
|
25
|
-
assert_equal "A",
|
25
|
+
assert_equal "A", Sohm::Command[:sinterstore, "A"]
|
26
26
|
end
|
27
27
|
|
28
28
|
test "full stack test" do |redis, nido|
|
29
|
-
cmd1 =
|
29
|
+
cmd1 = Sohm::Command[:sinterstore, "A", "B"]
|
30
30
|
|
31
31
|
res = cmd1.call(nido, redis)
|
32
32
|
assert_equal ["1"], redis.call("SMEMBERS", res)
|
@@ -34,8 +34,8 @@ scope do
|
|
34
34
|
cmd1.clean
|
35
35
|
assert_equal 0, redis.call("EXISTS", res)
|
36
36
|
|
37
|
-
cmd2 =
|
38
|
-
cmd3 =
|
37
|
+
cmd2 = Sohm::Command[:sinterstore, "C", "D", "E"]
|
38
|
+
cmd3 = Sohm::Command[:sunionstore, cmd1, cmd2]
|
39
39
|
|
40
40
|
res = cmd3.call(nido, redis)
|
41
41
|
assert_equal ["1", "12"], redis.call("SMEMBERS", res)
|
@@ -43,8 +43,8 @@ scope do
|
|
43
43
|
cmd3.clean
|
44
44
|
assert redis.call("KEYS", nido["*"]).empty?
|
45
45
|
|
46
|
-
cmd4 =
|
47
|
-
cmd5 =
|
46
|
+
cmd4 = Sohm::Command[:sinterstore, "F", "G", "H"]
|
47
|
+
cmd5 = Sohm::Command[:sdiffstore, cmd3, cmd4]
|
48
48
|
|
49
49
|
res = cmd5.call(nido, redis)
|
50
50
|
assert_equal ["1"], redis.call("SMEMBERS", res)
|
data/test/connection.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require_relative 'helper'
|
2
2
|
|
3
|
-
test "model inherits
|
4
|
-
class C <
|
3
|
+
test "model inherits Sohm.redis connection by default" do
|
4
|
+
class C < Sohm::Model
|
5
5
|
end
|
6
6
|
|
7
|
-
assert_equal C.redis.url,
|
7
|
+
assert_equal C.redis.url, Sohm.redis.url
|
8
8
|
end
|
9
9
|
|
10
10
|
test "model can define its own connection" do
|
11
|
-
class B <
|
11
|
+
class B < Sohm::Model
|
12
12
|
self.redis = Redic.new("redis://localhost:6379/1")
|
13
13
|
end
|
14
14
|
|
15
|
-
assert B.redis.url !=
|
15
|
+
assert B.redis.url != Sohm.redis.url
|
16
16
|
end
|
data/test/core.rb
CHANGED
data/test/counters.rb
CHANGED
data/test/enumerable.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative "helper"
|
2
2
|
|
3
3
|
scope do
|
4
|
-
class Contact <
|
4
|
+
class Contact < Sohm::Model
|
5
|
+
include Sohm::AutoId
|
6
|
+
include Sohm::IndexAll
|
7
|
+
|
5
8
|
attribute :name
|
6
9
|
end
|
7
10
|
|
@@ -37,10 +40,13 @@ scope do
|
|
37
40
|
end
|
38
41
|
|
39
42
|
scope do
|
40
|
-
class Comment <
|
43
|
+
class Comment < Sohm::Model
|
44
|
+
include Sohm::AutoId
|
41
45
|
end
|
42
46
|
|
43
|
-
class Post <
|
47
|
+
class Post < Sohm::Model
|
48
|
+
include Sohm::AutoId
|
49
|
+
|
44
50
|
list :comments, :Comment
|
45
51
|
end
|
46
52
|
|
data/test/filtering.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require_relative "helper"
|
2
2
|
|
3
|
-
class User <
|
3
|
+
class User < Sohm::Model
|
4
|
+
include Sohm::AutoId
|
5
|
+
include Sohm::IndexAll
|
6
|
+
|
4
7
|
attribute :fname
|
5
8
|
attribute :lname
|
6
9
|
attribute :status
|
@@ -35,16 +38,6 @@ test "sets aren't mutable" do |john, jane|
|
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
38
|
-
test "#first" do |john, jane|
|
39
|
-
set = User.find(:lname => "Doe", :status => "active")
|
40
|
-
|
41
|
-
assert_equal jane, set.first(:by => "fname", :order => "ALPHA")
|
42
|
-
assert_equal john, set.first(:by => "fname", :order => "ALPHA DESC")
|
43
|
-
|
44
|
-
assert_equal "Jane", set.first(:by => "fname", :order => "ALPHA", :get => "fname")
|
45
|
-
assert_equal "John", set.first(:by => "fname", :order => "ALPHA DESC", :get => "fname")
|
46
|
-
end
|
47
|
-
|
48
41
|
test "#[]" do |john, jane|
|
49
42
|
set = User.find(:lname => "Doe", :status => "active")
|
50
43
|
|
@@ -121,11 +114,15 @@ end
|
|
121
114
|
|
122
115
|
# book author thing via @myobie
|
123
116
|
scope do
|
124
|
-
class Book <
|
117
|
+
class Book < Sohm::Model
|
118
|
+
include Sohm::AutoId
|
119
|
+
|
125
120
|
collection :authors, :Author
|
126
121
|
end
|
127
122
|
|
128
|
-
class Author <
|
123
|
+
class Author < Sohm::Model
|
124
|
+
include Sohm::AutoId
|
125
|
+
|
129
126
|
reference :book, :Book
|
130
127
|
|
131
128
|
attribute :mood
|
data/test/hash_key.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -14,10 +14,12 @@ end unless defined?(silence_warnings)
|
|
14
14
|
|
15
15
|
$VERBOSE = true
|
16
16
|
|
17
|
-
require_relative "../lib/
|
17
|
+
require_relative "../lib/sohm"
|
18
|
+
require_relative "../lib/sohm/auto_id"
|
19
|
+
require_relative "../lib/sohm/index_all"
|
18
20
|
|
19
|
-
|
21
|
+
Sohm.redis = Redic.new("redis://127.0.0.1:6379")
|
20
22
|
|
21
23
|
prepare do
|
22
|
-
|
24
|
+
Sohm.redis.call("FLUSHALL")
|
23
25
|
end
|
data/test/indices.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative "helper"
|
2
2
|
|
3
|
-
class User <
|
3
|
+
class User < Sohm::Model
|
4
|
+
include Sohm::AutoId
|
5
|
+
|
4
6
|
attribute :email
|
5
7
|
attribute :update
|
6
8
|
attribute :activation_code
|
@@ -35,7 +37,7 @@ test "be able to find by the given attribute" do
|
|
35
37
|
end
|
36
38
|
|
37
39
|
test "raise if the index doesn't exist" do
|
38
|
-
assert_raise
|
40
|
+
assert_raise Sohm::IndexNotFound do
|
39
41
|
User.find(:address => "foo")
|
40
42
|
end
|
41
43
|
end
|
@@ -51,13 +53,13 @@ test "raise an error if the parameter supplied is not a hash" do
|
|
51
53
|
end
|
52
54
|
|
53
55
|
test "avoid intersections with the all collection" do
|
54
|
-
assert_equal "User:
|
56
|
+
assert_equal "User:_indices:email:foo", User.find(:email => "foo").key
|
55
57
|
end
|
56
58
|
|
57
59
|
test "cleanup the temporary key after use" do
|
58
60
|
assert User.find(:email => "foo", :activation_code => "bar").to_a
|
59
61
|
|
60
|
-
assert
|
62
|
+
assert Sohm.redis.call("KEYS", "User:temp:*").empty?
|
61
63
|
end
|
62
64
|
|
63
65
|
test "allow multiple chained finds" do
|
@@ -99,35 +101,3 @@ test "allow indexing by an arbitrary attribute" do
|
|
99
101
|
assert [@user1, @user2] == gmail.sort_by { |u| u.id }
|
100
102
|
assert [@user3] == User.find(:email_provider => "yahoo.com").to_a
|
101
103
|
end
|
102
|
-
|
103
|
-
scope do
|
104
|
-
# Just to give more context around this bug, basically it happens
|
105
|
-
# when you define a virtual unique or index.
|
106
|
-
#
|
107
|
-
# Previously it was unable to cleanup the indices mainly because
|
108
|
-
# it relied on the attributes being set.
|
109
|
-
class Node < Ohm::Model
|
110
|
-
index :available
|
111
|
-
attribute :capacity
|
112
|
-
|
113
|
-
unique :available
|
114
|
-
|
115
|
-
def available
|
116
|
-
capacity.to_i <= 90
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
test "index bug" do
|
121
|
-
n = Node.create
|
122
|
-
n.update(capacity: 91)
|
123
|
-
|
124
|
-
assert_equal 0, Node.find(available: true).size
|
125
|
-
end
|
126
|
-
|
127
|
-
test "uniques bug" do
|
128
|
-
n = Node.create
|
129
|
-
n.update(capacity: 91)
|
130
|
-
|
131
|
-
assert_equal nil, Node.with(:available, true)
|
132
|
-
end
|
133
|
-
end
|
data/test/json.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
require_relative 'helper'
|
2
|
-
require_relative "../lib/
|
2
|
+
require_relative "../lib/sohm/json"
|
3
|
+
|
4
|
+
class Venue < Sohm::Model
|
5
|
+
include Sohm::AutoId
|
3
6
|
|
4
|
-
class Venue < Ohm::Model
|
5
7
|
attribute :name
|
6
8
|
list :programmers, :Programmer
|
7
9
|
end
|
8
10
|
|
9
|
-
class Programmer <
|
11
|
+
class Programmer < Sohm::Model
|
12
|
+
include Sohm::AutoId
|
13
|
+
include Sohm::IndexAll
|
14
|
+
|
10
15
|
attribute :language
|
11
16
|
|
12
17
|
index :language
|
data/test/list.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require_relative "helper"
|
2
2
|
|
3
|
-
class Post <
|
3
|
+
class Post < Sohm::Model
|
4
|
+
include Sohm::AutoId
|
5
|
+
|
4
6
|
list :comments, :Comment
|
5
7
|
end
|
6
8
|
|
7
|
-
class Comment <
|
9
|
+
class Comment < Sohm::Model
|
10
|
+
include Sohm::AutoId
|
8
11
|
end
|
9
12
|
|
10
13
|
setup do
|
@@ -30,14 +33,6 @@ test "first / last / size / empty?" do |p, c1, c2, c3|
|
|
30
33
|
assert ! p.comments.empty?
|
31
34
|
end
|
32
35
|
|
33
|
-
test "replace" do |p, c1, c2, c3|
|
34
|
-
c4 = Comment.create
|
35
|
-
|
36
|
-
p.comments.replace([c4])
|
37
|
-
|
38
|
-
assert_equal [c4], p.comments.to_a
|
39
|
-
end
|
40
|
-
|
41
36
|
test "push / unshift" do |p, c1, c2, c3|
|
42
37
|
c4 = Comment.create
|
43
38
|
c5 = Comment.create
|
@@ -65,7 +60,7 @@ end
|
|
65
60
|
test "deleting main model cleans up the collection" do |p, _, _, _|
|
66
61
|
p.delete
|
67
62
|
|
68
|
-
assert_equal 0,
|
63
|
+
assert_equal 0, Sohm.redis.call("EXISTS", p.key[:comments])
|
69
64
|
end
|
70
65
|
|
71
66
|
test "#ids returns an array with the ids" do |post, *comments|
|