zebris 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +1 -0
- data/lib/zebris.rb +10 -1
- data/lib/zebris/document.rb +87 -52
- data/lib/zebris/serializers/json.rb +17 -0
- data/lib/zebris/types.rb +41 -9
- data/lib/zebris/version.rb +1 -1
- data/spec/lib/document_spec.rb +149 -144
- data/spec/lib/types_spec.rb +0 -17
- data/zebris.gemspec +1 -1
- metadata +24 -12
- checksums.yaml +0 -7
data/.travis.yml
ADDED
data/README.md
CHANGED
data/lib/zebris.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "zebris/version"
|
2
2
|
require "zebris/types"
|
3
3
|
require "zebris/document"
|
4
|
-
require
|
4
|
+
require "zebris/serializers/json"
|
5
5
|
|
6
6
|
module Zebris
|
7
7
|
def self.redis=(connection)
|
@@ -11,4 +11,13 @@ module Zebris
|
|
11
11
|
def self.redis
|
12
12
|
@redis
|
13
13
|
end
|
14
|
+
|
15
|
+
def self.serializer=(serializer)
|
16
|
+
raise "Not a zebris serializer" unless serializer.name.start_with?("Zebris::Serializers")
|
17
|
+
@serializer = serializer
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.serializer
|
21
|
+
@serializer ||= Zebris::Serializers::JSON
|
22
|
+
end
|
14
23
|
end
|
data/lib/zebris/document.rb
CHANGED
@@ -7,10 +7,9 @@ module Zebris
|
|
7
7
|
def save
|
8
8
|
raise "#{self.class} does not define a key generator" unless self.class.keygen.kind_of?(Proc)
|
9
9
|
|
10
|
-
self.class.scrub
|
11
10
|
data = self.class.serialize(self)
|
12
11
|
|
13
|
-
result = Zebris.redis.set self.key, data
|
12
|
+
result = Zebris.redis.set self.key, Zebris.serializer.serialize(data)
|
14
13
|
|
15
14
|
raise "Could not save #{self.class}" unless result == "OK"
|
16
15
|
|
@@ -28,55 +27,34 @@ module Zebris
|
|
28
27
|
|
29
28
|
def find(key)
|
30
29
|
stored = Zebris.redis.get key
|
31
|
-
|
32
|
-
if stored
|
33
|
-
data = JSON.parse(stored)
|
34
|
-
deserialize(data)
|
35
|
-
else
|
36
|
-
nil
|
37
|
-
end
|
30
|
+
stored ? deserialize(Zebris.serializer.deserialize(stored)) : nil
|
38
31
|
end
|
39
32
|
|
40
33
|
def serialize(object, embed = false)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if conversion.kind_of?(Zebris::Types::GenericConverter)
|
46
|
-
attributes[property.to_s] = conversion.serializer.call(val)
|
47
|
-
else
|
48
|
-
if conversion.ancestors.include?(Zebris::Document)
|
49
|
-
attributes[property.to_s] = conversion.serialize(val, true)
|
50
|
-
else
|
51
|
-
attributes[property.to_s] = conversion.serialize(val)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
collections.each do |property, klass|
|
58
|
-
raise "#{klass} does not implement the Zebris::Document interface" unless klass.ancestors.include?(Zebris::Document)
|
59
|
-
|
60
|
-
attributes[property] ||= []
|
61
|
-
object.send(:instance_variable_get, :"@#{property}").each do |record|
|
62
|
-
attributes[property] << klass.serialize(record, true)
|
63
|
-
end
|
34
|
+
scrub
|
35
|
+
(embed ? {} : {"key" => object.key}).tap do |attributes|
|
36
|
+
attributes.merge!(serialize_properties(object))
|
37
|
+
attributes.merge!(serialize_collections(object))
|
64
38
|
end
|
65
|
-
|
66
|
-
attributes
|
67
39
|
end
|
68
40
|
|
69
41
|
def scrub
|
70
42
|
unless @scrubbed
|
71
43
|
self.properties.each do |property, type|
|
72
44
|
unless type.kind_of?(Zebris::Types::GenericConverter)
|
73
|
-
|
74
|
-
|
45
|
+
resolved_type = case type
|
46
|
+
when Symbol
|
47
|
+
if zebris_type?(type)
|
48
|
+
Zebris::Types.const_get(type)
|
49
|
+
else
|
50
|
+
klass = lookup_class(type)
|
51
|
+
zebris_document?(klass) ? klass : Zebris::Types::BasicObject
|
52
|
+
end
|
53
|
+
else
|
54
|
+
zebris_document?(type) || zebris_type?(type) ? type : Zebris::Types::BasicObject
|
75
55
|
end
|
76
56
|
|
77
|
-
|
78
|
-
raise "#{type} does not implement the Zebris::Document interface"
|
79
|
-
end
|
57
|
+
self.properties[property] = resolved_type
|
80
58
|
end
|
81
59
|
end
|
82
60
|
|
@@ -103,9 +81,7 @@ module Zebris
|
|
103
81
|
instance.send(:"#{property}=", self.properties[property].deserialize(value))
|
104
82
|
end
|
105
83
|
elsif self.collections[property] && value.instance_of?(Array)
|
106
|
-
value.
|
107
|
-
instance.send(:"instance_variable_get", :"@#{property}") << self.collections[property].deserialize(row)
|
108
|
-
end
|
84
|
+
instance.send(:"instance_variable_set", :"@#{property}", value.map {|row| self.collections[property].deserialize(row)})
|
109
85
|
end
|
110
86
|
end
|
111
87
|
end
|
@@ -124,16 +100,8 @@ module Zebris
|
|
124
100
|
end
|
125
101
|
|
126
102
|
def property(name, type_or_serializer, deserializer = nil)
|
127
|
-
|
128
|
-
|
129
|
-
properties[name] = Zebris::Types::GenericConverter.new(type_or_serializer, deserializer)
|
130
|
-
else
|
131
|
-
if Zebris::Types.constants.include?(type_or_serializer.to_s.to_sym)
|
132
|
-
properties[name] = Zebris::Types.const_get(type_or_serializer.to_s.to_sym)
|
133
|
-
else
|
134
|
-
properties[name] = type_or_serializer
|
135
|
-
end
|
136
|
-
end
|
103
|
+
properties[name] = resolve_type(type_or_serializer, deserializer)
|
104
|
+
|
137
105
|
self.send(:attr_accessor, name)
|
138
106
|
end
|
139
107
|
|
@@ -148,6 +116,73 @@ module Zebris
|
|
148
116
|
self.send(:instance_variable_get, :"@#{name}") || self.send(:instance_variable_set, :"@#{name}", [])
|
149
117
|
}
|
150
118
|
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def resolve_type(type_or_serializer, deserializer)
|
123
|
+
if type_or_serializer.kind_of?(Proc)
|
124
|
+
raise "When providing a deserializer you need to provide a deserializer" if deserializer.nil?
|
125
|
+
Zebris::Types::GenericConverter.new(type_or_serializer, deserializer)
|
126
|
+
else
|
127
|
+
type = type_or_serializer.to_s.intern
|
128
|
+
|
129
|
+
if zebris_type?(type)
|
130
|
+
Zebris::Types.const_get(type)
|
131
|
+
elsif zebris_document?(type_or_serializer)
|
132
|
+
type_or_serializer
|
133
|
+
else
|
134
|
+
type
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def zebris_type?(type)
|
140
|
+
type.to_s.start_with?("Zebris::Types") || Zebris::Types.constants.include?(type)
|
141
|
+
end
|
142
|
+
|
143
|
+
def zebris_document?(klass)
|
144
|
+
klass.respond_to?(:ancestors) ? klass.ancestors.include?(Zebris::Document) : false
|
145
|
+
end
|
146
|
+
|
147
|
+
def lookup_class(type)
|
148
|
+
if self.constants.include?(type)
|
149
|
+
self.const_get(type)
|
150
|
+
elsif Module.constants.include?(type)
|
151
|
+
Module.const_get(type)
|
152
|
+
else
|
153
|
+
raise "Could not find class #{type}"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def serialize_properties(target)
|
158
|
+
Hash.new.tap do |attributes|
|
159
|
+
properties.each do |property, conversion|
|
160
|
+
if val = target.send(property.to_sym)
|
161
|
+
if conversion.kind_of?(Zebris::Types::GenericConverter)
|
162
|
+
attributes[property.to_s] = conversion.serializer.call(val)
|
163
|
+
else
|
164
|
+
if conversion.ancestors.include?(Zebris::Document)
|
165
|
+
attributes[property.to_s] = conversion.serialize(val, true)
|
166
|
+
else
|
167
|
+
attributes[property.to_s] = conversion.serialize(val)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def serialize_collections(target)
|
176
|
+
Hash.new() {|hash, key| hash[key] = []}.tap do |attributes|
|
177
|
+
collections.each do |property, klass|
|
178
|
+
raise "#{klass} does not implement the Zebris::Document interface" unless klass.ancestors.include?(Zebris::Document)
|
179
|
+
target.send(:instance_variable_set, :"@#{property}", []) unless target.send(:instance_variable_get, :"@#{property}")
|
180
|
+
target.send(:instance_variable_get, :"@#{property}").each do |record|
|
181
|
+
attributes[property] << klass.serialize(record, true)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
151
186
|
end
|
152
187
|
end
|
153
188
|
end
|
data/lib/zebris/types.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'time'
|
3
|
+
|
1
4
|
module Zebris
|
2
5
|
module Types
|
3
6
|
class GenericConverter
|
@@ -9,29 +12,58 @@ module Zebris
|
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
15
|
+
class BasicObject
|
16
|
+
def self.b(val)
|
17
|
+
val
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.deserialize(value)
|
21
|
+
value
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.serialize(value)
|
25
|
+
value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
12
29
|
class Date
|
13
30
|
def self.deserialize(date)
|
14
31
|
::Date.parse(date)
|
15
32
|
end
|
16
33
|
|
17
34
|
def self.serialize(val)
|
18
|
-
val.
|
35
|
+
raise "#{val} not a valid Date" unless val.respond_to?(:to_time)
|
36
|
+
|
37
|
+
Time.serialize(val.to_time)
|
19
38
|
end
|
20
39
|
end
|
21
40
|
|
22
|
-
class
|
23
|
-
def self.deserialize(
|
24
|
-
(
|
41
|
+
class Time
|
42
|
+
def self.deserialize(time)
|
43
|
+
::Time.parse(date)
|
25
44
|
end
|
26
45
|
|
27
46
|
def self.serialize(val)
|
28
|
-
val
|
47
|
+
raise "#{val} not a valid Time" unless val.kind_of?(::Time)
|
48
|
+
val.to_time.rfc2822
|
29
49
|
end
|
30
50
|
end
|
31
51
|
|
32
|
-
class
|
52
|
+
class DateTime
|
53
|
+
def self.deserialize(date)
|
54
|
+
::DateTime.parse(date)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.serialize(val)
|
58
|
+
raise "#{val} not a valid DateTime" unless val.respond_to?(:to_time)
|
59
|
+
|
60
|
+
Time.serialize(val.to_time)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Integer
|
33
65
|
def self.deserialize(val)
|
34
|
-
(val && val != "") ? val.
|
66
|
+
(val && val != "") ? val.to_i : nil
|
35
67
|
end
|
36
68
|
|
37
69
|
def self.serialize(val)
|
@@ -39,9 +71,9 @@ module Zebris
|
|
39
71
|
end
|
40
72
|
end
|
41
73
|
|
42
|
-
class
|
74
|
+
class Float
|
43
75
|
def self.deserialize(val)
|
44
|
-
val ? val.
|
76
|
+
(val && val != "") ? val.to_f : nil
|
45
77
|
end
|
46
78
|
|
47
79
|
def self.serialize(val)
|
data/lib/zebris/version.rb
CHANGED
data/spec/lib/document_spec.rb
CHANGED
@@ -2,209 +2,214 @@ require_relative "../../lib/zebris"
|
|
2
2
|
require 'uuid'
|
3
3
|
|
4
4
|
describe Zebris::Document do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
property :last_update, Date
|
11
|
-
end
|
12
|
-
|
13
|
-
class KeylessDocument
|
14
|
-
include Zebris::Document
|
15
|
-
property :name, String
|
16
|
-
end
|
5
|
+
let!(:redis) {double(:redis, set: "OK", get: true)}
|
6
|
+
let(:key) {"ABCDEFG"}
|
7
|
+
let(:name) {"John Henry"}
|
8
|
+
let(:age) {34}
|
9
|
+
let(:last_update) {Date.today - 2}
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
key {UUID.generate}
|
21
|
-
property :name, lambda {|n| n}, lambda {|n| String.new(n)}
|
11
|
+
before do
|
12
|
+
Zebris.redis = redis
|
22
13
|
end
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
key {UUID.generate}
|
27
|
-
property :person, Person
|
28
|
-
|
29
|
-
class Person
|
15
|
+
context "for simple documents" do
|
16
|
+
class Document
|
30
17
|
include Zebris::Document
|
31
18
|
key {UUID.generate}
|
32
19
|
property :name, String
|
33
20
|
property :age, Integer
|
21
|
+
property :last_update, Date
|
34
22
|
end
|
35
|
-
end
|
36
23
|
|
37
|
-
|
38
|
-
|
24
|
+
it "should persist a document with a name property" do
|
25
|
+
document = Document.new
|
26
|
+
document.stub(:key).and_return(key)
|
27
|
+
redis.should_receive(:set).with(key, {"key" => key, "name" => name}.to_json)
|
39
28
|
|
40
|
-
|
29
|
+
document.name = name
|
30
|
+
document.save
|
31
|
+
end
|
41
32
|
|
42
|
-
|
33
|
+
it "properly serializes the built in types" do
|
34
|
+
document = Document.new
|
35
|
+
document.stub(:key).and_return(key)
|
36
|
+
redis.should_receive(:set).with(key, {"key" => key, "name" => name, "age" => age, "last_update" => last_update.to_time.rfc2822}.to_json)
|
43
37
|
|
44
|
-
|
45
|
-
|
38
|
+
document.name = name
|
39
|
+
document.age = age
|
40
|
+
document.last_update = last_update
|
41
|
+
document.save
|
42
|
+
end
|
43
|
+
end
|
46
44
|
|
45
|
+
context "complicated documents" do
|
46
|
+
class KeylessDocument
|
47
|
+
include Zebris::Document
|
47
48
|
property :name, String
|
48
|
-
property :age, Integer
|
49
49
|
end
|
50
|
-
end
|
51
50
|
|
52
|
-
|
53
|
-
|
51
|
+
class LambdaDocument
|
52
|
+
include Zebris::Document
|
53
|
+
key {UUID.generate}
|
54
|
+
property :name, lambda {|n| n}, lambda {|n| String.new(n)}
|
55
|
+
end
|
54
56
|
|
55
|
-
|
57
|
+
class BasicObjectDocument
|
58
|
+
include Zebris::Document
|
56
59
|
|
57
|
-
|
60
|
+
key {UUID.generate}
|
58
61
|
|
59
|
-
|
62
|
+
property :ids, Array
|
60
63
|
end
|
61
|
-
end
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
let(:last_update) {Date.today - 2}
|
65
|
+
class NestedDocument
|
66
|
+
include Zebris::Document
|
67
|
+
key {UUID.generate}
|
68
|
+
property :person, Person
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
class Person
|
71
|
+
include Zebris::Document
|
72
|
+
key {UUID.generate}
|
73
|
+
property :name, String
|
74
|
+
property :age, Integer
|
75
|
+
end
|
76
|
+
end
|
72
77
|
|
73
|
-
|
74
|
-
|
75
|
-
document = Document.new
|
76
|
-
document.stub(:key).and_return(key)
|
77
|
-
redis.should_receive(:set).with(key, {"key" => key, "name" => name}.to_json)
|
78
|
+
class CollectionDocument
|
79
|
+
include Zebris::Document
|
78
80
|
|
79
|
-
|
80
|
-
document.save
|
81
|
-
end
|
81
|
+
key {UUID.generate}
|
82
82
|
|
83
|
-
|
84
|
-
document = KeylessDocument.new
|
85
|
-
document.name = name
|
86
|
-
expect{document.save}.to raise_exception
|
87
|
-
end
|
83
|
+
collection :people, Person
|
88
84
|
|
89
|
-
|
90
|
-
|
91
|
-
document = Document.new
|
92
|
-
document.stub(:key).and_return(key)
|
93
|
-
redis.should_receive(:set).with(key, {"key" => key, "name" => name, "age" => age, "last_update" => last_update.rfc3339}.to_json)
|
85
|
+
class Person
|
86
|
+
include Zebris::Document
|
94
87
|
|
95
|
-
|
96
|
-
|
97
|
-
document.last_update = last_update
|
98
|
-
document.save
|
88
|
+
property :name, String
|
89
|
+
property :age, Integer
|
99
90
|
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class InvalidCollectionDocument
|
94
|
+
include Zebris::Document
|
100
95
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
redis.should_receive(:set).with(key, {"key" => key, "name" => name}.to_json)
|
96
|
+
key {UUID.generate}
|
97
|
+
|
98
|
+
collection :people, Person
|
105
99
|
|
100
|
+
class Person
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "saving documents" do
|
105
|
+
it "raises an error when trying to save a document without a key generator" do
|
106
|
+
document = KeylessDocument.new
|
106
107
|
document.name = name
|
107
|
-
document.save
|
108
|
+
expect{document.save}.to raise_exception
|
108
109
|
end
|
109
110
|
|
110
|
-
context "
|
111
|
-
it "serializes
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
person.age = age
|
116
|
-
person.stub(:key).and_return(person_key)
|
111
|
+
context "property types" do
|
112
|
+
it "properly serializes the data when given a lambda" do
|
113
|
+
document = LambdaDocument.new
|
114
|
+
document.stub(:key).and_return(key)
|
115
|
+
redis.should_receive(:set).with(key, {"key" => key, "name" => name}.to_json)
|
117
116
|
|
118
|
-
|
117
|
+
document.name = name
|
118
|
+
document.save
|
119
|
+
end
|
119
120
|
|
120
|
-
|
121
|
+
it "uses the Zebris::Types::BasicObject serializer for unknown property types" do
|
122
|
+
document = BasicObjectDocument.new
|
121
123
|
document.stub(:key).and_return(key)
|
122
|
-
|
124
|
+
redis.should_receive(:set).with(key, {"key" => key, "ids" => [1, 2, 3]}.to_json)
|
125
|
+
|
126
|
+
document.ids = [1, 2, 3]
|
123
127
|
document.save
|
124
128
|
end
|
125
129
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
130
|
+
context "nested type collections" do
|
131
|
+
it "serializes nested types if they include Zebris::Document" do
|
132
|
+
person_key = "123456"
|
133
|
+
person = NestedDocument::Person.new
|
134
|
+
person.name = name
|
135
|
+
person.age = age
|
136
|
+
person.stub(:key).and_return(person_key)
|
131
137
|
|
132
|
-
|
133
|
-
end
|
138
|
+
redis.should_receive(:set).with(key, {"key" => key, "person" => {"name" => name, "age" => age}}.to_json)
|
134
139
|
|
135
|
-
|
136
|
-
document
|
137
|
-
document.person =
|
140
|
+
document = NestedDocument.new
|
141
|
+
document.stub(:key).and_return(key)
|
142
|
+
document.person = person
|
138
143
|
document.save
|
139
|
-
|
144
|
+
end
|
140
145
|
end
|
141
|
-
end
|
142
146
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
147
|
+
context "collections" do
|
148
|
+
it "serializes each item in a collection properly" do
|
149
|
+
document = CollectionDocument.new
|
150
|
+
document.stub(:key).and_return(key)
|
151
|
+
redis.should_receive(:set).with(key, {"key" => key, "people" => [{"name" => name, "age" => age}]}.to_json)
|
148
152
|
|
149
|
-
|
150
|
-
|
151
|
-
|
153
|
+
p = CollectionDocument::Person.new
|
154
|
+
p.name = name
|
155
|
+
p.age = age
|
152
156
|
|
153
|
-
|
154
|
-
|
155
|
-
|
157
|
+
document.people << p
|
158
|
+
document.save
|
159
|
+
end
|
156
160
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
+
it "raises an error if the serialization type does not support the Zebris::Document interface" do
|
162
|
+
document = InvalidCollectionDocument.new
|
163
|
+
document.stub(:key).and_return(key)
|
164
|
+
document.people << InvalidCollectionDocument::Person.new
|
161
165
|
|
162
|
-
|
163
|
-
|
164
|
-
|
166
|
+
expect {
|
167
|
+
expect document.save
|
168
|
+
}.to raise_exception
|
169
|
+
end
|
165
170
|
end
|
166
171
|
end
|
167
172
|
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "restoring documents" do
|
171
|
-
let(:serialized_document) {{"key" => key, "name" => name}.to_json}
|
172
|
-
let(:types_serialized_document) {{"key" => key, "name" => name, "age" => age, "last_update" => last_update.rfc3339}.to_json}
|
173
|
-
let(:lambda_serialized_document) {{"key" => key, "name" => name}.to_json}
|
174
|
-
let(:nested_serialized_document) {{"key" => key, "person" => {"name" => name, "age" => age}}.to_json}
|
175
173
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
174
|
+
context "restoring documents" do
|
175
|
+
let(:serialized_document) {{"key" => key, "name" => name}.to_json}
|
176
|
+
let(:types_serialized_document) {{"key" => key, "name" => name, "age" => age, "last_update" => last_update.rfc3339}.to_json}
|
177
|
+
let(:lambda_serialized_document) {{"key" => key, "name" => name}.to_json}
|
178
|
+
let(:nested_serialized_document) {{"key" => key, "person" => {"name" => name, "age" => age}}.to_json}
|
180
179
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
end
|
180
|
+
it "delegates to the redis object" do
|
181
|
+
redis.should_receive(:get).with(key).and_return(serialized_document)
|
182
|
+
Document.find(key)
|
183
|
+
end
|
186
184
|
|
187
|
-
|
188
|
-
|
189
|
-
redis.stub(:get).and_return(types_serialized_document)
|
185
|
+
it "rebuilds an object that has been saved to redis" do
|
186
|
+
redis.stub(:get).and_return(serialized_document)
|
190
187
|
document = Document.find(key)
|
191
188
|
expect(document.name).to eq(name)
|
192
|
-
expect(document.age).to eq(age)
|
193
|
-
expect(document.last_update).to eq(last_update)
|
194
189
|
end
|
195
190
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
191
|
+
context "property types" do
|
192
|
+
it "rebuilds an object using built-in types" do
|
193
|
+
redis.stub(:get).and_return(types_serialized_document)
|
194
|
+
document = Document.find(key)
|
195
|
+
expect(document.name).to eq(name)
|
196
|
+
expect(document.age).to eq(age)
|
197
|
+
expect(document.last_update).to eq(last_update)
|
198
|
+
end
|
201
199
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
document
|
206
|
-
|
207
|
-
|
200
|
+
it "rebuilds an object using lambda serializers/deserializers" do
|
201
|
+
redis.stub(:get).and_return(lambda_serialized_document)
|
202
|
+
document = LambdaDocument.find(key)
|
203
|
+
expect(document.name).to eq(name)
|
204
|
+
end
|
205
|
+
|
206
|
+
context "nested documents" do
|
207
|
+
it "rebuilds a nested object structure" do
|
208
|
+
redis.stub(:get).and_return(nested_serialized_document)
|
209
|
+
document = NestedDocument.find(key)
|
210
|
+
expect(document.person.name).to eq(name)
|
211
|
+
expect(document.person.age).to eq(age)
|
212
|
+
end
|
208
213
|
end
|
209
214
|
end
|
210
215
|
end
|
data/spec/lib/types_spec.rb
CHANGED
@@ -57,21 +57,4 @@ describe Zebris::Types do
|
|
57
57
|
expect{Zebris::Types::Float.deserialize(o)}.to raise_exception
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
61
|
-
context Zebris::Types::String do
|
62
|
-
it "deserializes and returns a string as itself" do
|
63
|
-
s = %q{Do the ham bone}
|
64
|
-
expect(Zebris::Types::String.deserialize(s)).to eq(s)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "deserializes and returns nil as nil" do
|
68
|
-
s = nil
|
69
|
-
expect(Zebris::Types::String.deserialize(s)).to eq(nil)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "raises an exception if the object does not support being converted to a string" do
|
73
|
-
o = BasicObject.new
|
74
|
-
expect{Zebris::Types::String.deserialize(o)}.to raise_exception
|
75
|
-
end
|
76
|
-
end
|
77
60
|
end
|
data/zebris.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["jgailor@gmail.com"]
|
11
11
|
spec.description = %q{Zebris is a library to persist your object data to Redis. Its goal is to be as unobtrusive as possible.}
|
12
12
|
spec.summary = %q{Zebris makes persisting your objects to Redis easy.}
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "http://github.com/JGailor/zebris"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zebris
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Jeremy Gailor
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,20 +30,23 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '0'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - '>='
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '0'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rspec
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ~>
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -55,15 +62,17 @@ dependencies:
|
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: uuid
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
|
-
- - '>='
|
67
|
+
- - ! '>='
|
60
68
|
- !ruby/object:Gem::Version
|
61
69
|
version: '0'
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
|
-
- - '>='
|
75
|
+
- - ! '>='
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: '0'
|
69
78
|
description: Zebris is a library to persist your object data to Redis. Its goal is
|
@@ -75,40 +84,43 @@ extensions: []
|
|
75
84
|
extra_rdoc_files: []
|
76
85
|
files:
|
77
86
|
- .gitignore
|
87
|
+
- .travis.yml
|
78
88
|
- Gemfile
|
79
89
|
- LICENSE.txt
|
80
90
|
- README.md
|
81
91
|
- Rakefile
|
82
92
|
- lib/zebris.rb
|
83
93
|
- lib/zebris/document.rb
|
94
|
+
- lib/zebris/serializers/json.rb
|
84
95
|
- lib/zebris/types.rb
|
85
96
|
- lib/zebris/version.rb
|
86
97
|
- spec/lib/document_spec.rb
|
87
98
|
- spec/lib/types_spec.rb
|
88
99
|
- zebris.gemspec
|
89
|
-
homepage:
|
100
|
+
homepage: http://github.com/JGailor/zebris
|
90
101
|
licenses:
|
91
102
|
- MIT
|
92
|
-
metadata: {}
|
93
103
|
post_install_message:
|
94
104
|
rdoc_options: []
|
95
105
|
require_paths:
|
96
106
|
- lib
|
97
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
98
109
|
requirements:
|
99
|
-
- - '>='
|
110
|
+
- - ! '>='
|
100
111
|
- !ruby/object:Gem::Version
|
101
112
|
version: '0'
|
102
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
103
115
|
requirements:
|
104
|
-
- - '>='
|
116
|
+
- - ! '>='
|
105
117
|
- !ruby/object:Gem::Version
|
106
118
|
version: '0'
|
107
119
|
requirements: []
|
108
120
|
rubyforge_project:
|
109
|
-
rubygems_version:
|
121
|
+
rubygems_version: 1.8.23
|
110
122
|
signing_key:
|
111
|
-
specification_version:
|
123
|
+
specification_version: 3
|
112
124
|
summary: Zebris makes persisting your objects to Redis easy.
|
113
125
|
test_files:
|
114
126
|
- spec/lib/document_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 3b41c71b77c9cb0ad27d3ebc402203f2d0900a04
|
4
|
-
data.tar.gz: 12550a668b6b8701e9923b6764b3cc7ab00a6ef7
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 03dec832c90d045b163edab0d0bc4748db9211fb07254ebe4058417675639339239ef23f37f5ae8f9aa125ebd4f7ce1b0975230052016fcb92bb5a785f04a840
|
7
|
-
data.tar.gz: 9b7be6818cbbf39b4298b1a67d518ab55d8c356ddc99881d83dafd6995976e7ad1bdb20893bed0f9725dab12151c7d2d506ed199bcfc0a7d9b65dcec3cb80e25
|