ohm 2.0.0.alpha3 → 2.0.0.alpha4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/ohm.rb +2 -1
- data/lib/ohm/lua/delete.lua +24 -3
- data/lib/ohm/lua/save.lua +37 -8
- data/makefile +4 -0
- data/ohm.gemspec +1 -1
- data/test/model.rb +7 -0
- data/test/uniques.rb +6 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0098b213347fa1dade66ecb25578c98661dede1f
|
4
|
+
data.tar.gz: bf14fe6201dcc44633250fe1c76efd1ee9319d41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6452603dcdc4f3d0d822243c6d85d30d73d012f3521d04f673c5c53a8d71e6a153b7fada6420f889ef389f50e2d0ad2994b2985c239820471270a3d4c0410114
|
7
|
+
data.tar.gz: f1877e6cc349845df64382b0aa65f9f61955db0dd28f5e41ca47b6047d5625eb44b8bafbb0a1bb46dc0136641d98ebf786077f322672e8552d4edf323113bcca
|
data/README.md
CHANGED
@@ -443,8 +443,7 @@ lookups.
|
|
443
443
|
In the `Event` example, the index on the name attribute will
|
444
444
|
allow for searches like `Event.find(:name => "some value")`.
|
445
445
|
|
446
|
-
Note that the {Ohm::Model::
|
447
|
-
validation and the methods {Ohm::Model::Set#find find} and
|
446
|
+
Note that the methods {Ohm::Model::Set#find find} and
|
448
447
|
{Ohm::Model::Set#except except} need a corresponding index in order to work.
|
449
448
|
|
450
449
|
### Finding records
|
data/lib/ohm.rb
CHANGED
data/lib/ohm/lua/delete.lua
CHANGED
@@ -1,6 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
-- This script receives three parameters, all encoded with
|
2
|
+
-- MessagePack. The decoded values are used for deleting a model
|
3
|
+
-- instance in Redis and removing any reference to it in sets
|
4
|
+
-- (indices) and hashes (unique indices).
|
5
|
+
--
|
6
|
+
-- # model
|
7
|
+
--
|
8
|
+
-- Table with three attributes:
|
9
|
+
-- id (model instance id)
|
10
|
+
-- key (hash where the attributes will be saved)
|
11
|
+
-- name (model name)
|
12
|
+
--
|
13
|
+
-- # uniques
|
14
|
+
--
|
15
|
+
-- Fields and values to be removed from the unique indices.
|
16
|
+
--
|
17
|
+
-- # tracked
|
18
|
+
--
|
19
|
+
-- Keys that share the lifecycle of this model instance, that
|
20
|
+
-- should be removed as this object is deleted.
|
21
|
+
--
|
22
|
+
local model = cmsgpack.unpack(ARGV[1])
|
23
|
+
local uniques = cmsgpack.unpack(ARGV[2])
|
24
|
+
local tracked = cmsgpack.unpack(ARGV[3])
|
4
25
|
|
5
26
|
local function remove_indices(model)
|
6
27
|
local memo = model.key .. ":_indices"
|
data/lib/ohm/lua/save.lua
CHANGED
@@ -1,7 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
-- This script receives four parameters, all encoded with
|
2
|
+
-- MessagePack. The decoded values are used for saving a model
|
3
|
+
-- instance in Redis, creating or updating a hash as needed and
|
4
|
+
-- updating zero or more sets (indices) and zero or more hashes
|
5
|
+
-- (unique indices).
|
6
|
+
--
|
7
|
+
-- # model
|
8
|
+
--
|
9
|
+
-- Table with three attributes:
|
10
|
+
-- id (model instance id)
|
11
|
+
-- key (hash where the attributes will be saved)
|
12
|
+
-- name (model name)
|
13
|
+
--
|
14
|
+
-- # attrs
|
15
|
+
--
|
16
|
+
-- Array with attribute/value pairs.
|
17
|
+
--
|
18
|
+
-- # indices
|
19
|
+
--
|
20
|
+
-- Fields and values to be indexed. Each key in the indices
|
21
|
+
-- table is mapped to an array of values. One index is created
|
22
|
+
-- for each field/value pair.
|
23
|
+
--
|
24
|
+
-- # uniques
|
25
|
+
--
|
26
|
+
-- Fields and values to be indexed as unique. Unlike indices,
|
27
|
+
-- values are not enumerable. If a field/value pair is not unique
|
28
|
+
-- (i.e., if there was already a hash entry for that field and
|
29
|
+
-- value), an error is returned with the UniqueIndexViolation
|
30
|
+
-- message and the field that triggered the error.
|
31
|
+
--
|
32
|
+
local model = cmsgpack.unpack(ARGV[1])
|
33
|
+
local attrs = cmsgpack.unpack(ARGV[2])
|
34
|
+
local indices = cmsgpack.unpack(ARGV[3])
|
35
|
+
local uniques = cmsgpack.unpack(ARGV[4])
|
5
36
|
|
6
37
|
local function save(model, attrs)
|
7
38
|
redis.call("SADD", model.name .. ":all", model.id)
|
@@ -46,12 +77,10 @@ local function unique(model, uniques)
|
|
46
77
|
end
|
47
78
|
end
|
48
79
|
|
49
|
-
local function remove_uniques(model
|
80
|
+
local function remove_uniques(model)
|
50
81
|
local memo = model.key .. ":_uniques"
|
51
82
|
|
52
|
-
for
|
53
|
-
local key = model.name .. ":uniques:" .. field
|
54
|
-
|
83
|
+
for _, key in pairs(redis.call("HKEYS", memo)) do
|
55
84
|
redis.call("HDEL", key, redis.call("HGET", memo, key))
|
56
85
|
redis.call("HDEL", memo, key)
|
57
86
|
end
|
data/makefile
ADDED
data/ohm.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "ohm"
|
3
|
-
s.version = "2.0.0.
|
3
|
+
s.version = "2.0.0.alpha4"
|
4
4
|
s.summary = %{Object-hash mapping library for Redis.}
|
5
5
|
s.description = %Q{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.}
|
6
6
|
s.authors = ["Michel Martens", "Damian Janowski", "Cyril David"]
|
data/test/model.rb
CHANGED
@@ -42,6 +42,10 @@ module SomeNamespace
|
|
42
42
|
class Foo < Ohm::Model
|
43
43
|
attribute :name
|
44
44
|
end
|
45
|
+
|
46
|
+
class Bar < Ohm::Model
|
47
|
+
reference :foo, 'SomeNamespace::Foo'
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
class Meetup < Ohm::Model
|
@@ -779,9 +783,12 @@ end
|
|
779
783
|
test "be persisted" do
|
780
784
|
SomeNamespace::Foo.create(:name => "foo")
|
781
785
|
|
786
|
+
SomeNamespace::Bar.create(:foo => SomeNamespace::Foo[1])
|
787
|
+
|
782
788
|
assert "hash" == Ohm.redis.call("TYPE", "SomeNamespace::Foo:1")
|
783
789
|
|
784
790
|
assert "foo" == SomeNamespace::Foo[1].name
|
791
|
+
assert "foo" == SomeNamespace::Bar[1].foo.name
|
785
792
|
end
|
786
793
|
|
787
794
|
test "typecast attributes" do
|
data/test/uniques.rb
CHANGED
@@ -12,7 +12,7 @@ class User < Ohm::Model
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def provider
|
15
|
-
email[/@(.*?).com/, 1]
|
15
|
+
email.to_s[/@(.*?).com/, 1]
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -66,6 +66,11 @@ test "removes the previous index when changing" do
|
|
66
66
|
assert_equal nil, User.with(:email, "c@c.com")
|
67
67
|
assert_equal nil, User.redis.call("HGET", User.key[:uniques][:email], "c@c.com")
|
68
68
|
assert_equal u, User.with(:email, "d@d.com")
|
69
|
+
|
70
|
+
u.update(:email => nil)
|
71
|
+
|
72
|
+
assert_equal nil, User.with(:email, "d@d.com")
|
73
|
+
assert_equal nil, User.redis.call("HGET", User.key[:uniques][:email], "d@d.com")
|
69
74
|
end
|
70
75
|
|
71
76
|
test "removes the previous index when deleting" do |u|
|
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: 2.0.0.
|
4
|
+
version: 2.0.0.alpha4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redic
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/ohm/json.rb
|
102
102
|
- lib/ohm/lua/delete.lua
|
103
103
|
- lib/ohm/lua/save.lua
|
104
|
+
- makefile
|
104
105
|
- ohm.gemspec
|
105
106
|
- test/association.rb
|
106
107
|
- test/command.rb
|
@@ -145,3 +146,4 @@ signing_key:
|
|
145
146
|
specification_version: 4
|
146
147
|
summary: Object-hash mapping library for Redis.
|
147
148
|
test_files: []
|
149
|
+
has_rdoc:
|