hypostasis-repository 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12c33d8988e35799868170d62ed72c23bab5a8cd
|
4
|
+
data.tar.gz: 294dca4dcfe52b6aa5d38a6188b998ce2d86a0e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9100385603632b19029a40087729c8073837e6c2e355dbf1c2b3519049ed1909e817536642d330aca20493c677363ebcf6d09deb11bd37c1ff80d4467e632d2b
|
7
|
+
data.tar.gz: 8208990bd31f48c6cac2c031d2984a5eaa11b9fe71f4e977d0b20a61f197aa2205e5fccdc7b219c1ee42b658929a931e7b75f9ce60aeae7c7e193eb4a45f5fc3
|
@@ -25,11 +25,12 @@ module Hypostasis
|
|
25
25
|
object.instance_variable_set(:@hypostasis_repository_id, repo_id)
|
26
26
|
@hypostasis[:database].transact do |tr|
|
27
27
|
tr.clear_range_start_with(object_space)
|
28
|
+
instance_variables = {}
|
28
29
|
object.instance_variables.each do |ivar|
|
29
30
|
next if ivar == :@hypostasis_repository_id
|
30
|
-
|
31
|
-
tr.set(object_space[ivar.to_s], value)
|
31
|
+
instance_variables[ivar.to_s.gsub(/@/, '')] = object.instance_variable_get(ivar)
|
32
32
|
end
|
33
|
+
tr.set(object_space, MessagePack.pack(instance_variables))
|
33
34
|
end
|
34
35
|
object
|
35
36
|
end
|
@@ -37,8 +38,8 @@ module Hypostasis
|
|
37
38
|
def find(klass, criteria)
|
38
39
|
if criteria.is_a?(String)
|
39
40
|
find_by_id(klass, criteria)
|
40
|
-
elsif criteria.is_a?(Hash)
|
41
|
-
|
41
|
+
#elsif criteria.is_a?(Hash)
|
42
|
+
# ...
|
42
43
|
else
|
43
44
|
raise ArgumentError, 'criteria must be a String or Hash'
|
44
45
|
end
|
@@ -71,9 +72,9 @@ module Hypostasis
|
|
71
72
|
|
72
73
|
object = klass.new
|
73
74
|
object.instance_variable_set(:@hypostasis_repository_id, object_id)
|
74
|
-
results.
|
75
|
-
|
76
|
-
object.instance_variable_set(ivar,
|
75
|
+
instance_variables = MessagePack.unpack(results.first.value)
|
76
|
+
instance_variables.each do |ivar, value|
|
77
|
+
object.instance_variable_set("@#{ivar}".to_sym, value)
|
77
78
|
end
|
78
79
|
|
79
80
|
object
|
@@ -6,7 +6,8 @@ describe SimpleRepository do
|
|
6
6
|
let(:directory) { ::FDB.directory.open(database, %w{simple repository}) }
|
7
7
|
|
8
8
|
let(:subject) { SimpleRepository.new }
|
9
|
-
let(:
|
9
|
+
let(:attributes) { {name: 'John', dob: '1982-05-19', notes: 'An example'} }
|
10
|
+
let(:object) { Simple.new(attributes) }
|
10
11
|
|
11
12
|
before :each do
|
12
13
|
subject
|
@@ -26,16 +27,14 @@ describe SimpleRepository do
|
|
26
27
|
|
27
28
|
describe 'storage' do
|
28
29
|
let(:result) { subject.store(object) }
|
30
|
+
let(:value) { database.get(directory[object.class.to_s][@id]).value }
|
29
31
|
|
30
32
|
before :each do
|
31
33
|
result
|
32
34
|
@id = object.instance_variable_get(:@hypostasis_repository_id).encode(Encoding::US_ASCII)
|
33
35
|
end
|
34
36
|
|
35
|
-
it {
|
36
|
-
it { database.get(directory[object.class.to_s][@id][:@dob.to_s]).value.should eq '1982-05-19'.to_msgpack }
|
37
|
-
it { database.get(directory[object.class.to_s][@id][:@notes.to_s]).value.should eq 'An example'.to_msgpack }
|
38
|
-
it { database.get(directory[object.class.to_s][@id][:@hypostasis_repository_id.to_s]).should be_nil }
|
37
|
+
it { MessagePack.unpack(value).should eq MessagePack.unpack(MessagePack.pack(attributes)) }
|
39
38
|
it { result.should eq object }
|
40
39
|
end
|
41
40
|
|