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: ccf39be3829346b7de29e2a3a46a0e714e8cbd98
4
- data.tar.gz: 780805f2447594aeb21bbbd2495b112594f4c1ad
3
+ metadata.gz: 12c33d8988e35799868170d62ed72c23bab5a8cd
4
+ data.tar.gz: 294dca4dcfe52b6aa5d38a6188b998ce2d86a0e8
5
5
  SHA512:
6
- metadata.gz: b08a6b00ff5bb2e08edc1446d2868d481ba69e567d736dc380dfc9345b6349be92f2e5b1f2ba33647e6b0de4361b62b33d0824802b12b7f479ec3a557637142c
7
- data.tar.gz: ae339d7118e2ab5ecad627c9a5e87661ec7ab0fd8a41c9740712acb6a35fe42de91d6ee26ce1fee0e814d1ec4b59ed3244c8536c497edb501355a891bf8f50cb
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
- value = object.instance_variable_get(ivar).to_msgpack
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.each do |key|
75
- ivar = object_space.unpack(key.key)[0].to_sym
76
- object.instance_variable_set(ivar, MessagePack.unpack(key.value))
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
@@ -1,5 +1,5 @@
1
1
  module Hypostasis
2
2
  module Repository
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -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(:object) { Simple.new(name: 'John', dob: '1982-05-19', notes: 'An example') }
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 { database.get(directory[object.class.to_s][@id][:@name.to_s]).value.should eq 'John'.to_msgpack }
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hypostasis-repository
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Thompson