store 0.0.6 → 0.0.7

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: 6f95b1ab0e7baa12a07c3b53d297f42da47440ac
4
- data.tar.gz: 0dcaa59a8fe5af7d4678bb9ab714c335cd95894d
3
+ metadata.gz: 4b8b967c6d3ba58a8051a867938a7b4d27bfafb0
4
+ data.tar.gz: de319d311003addd0b4ba4d23a49b2cf6d1bbad5
5
5
  SHA512:
6
- metadata.gz: a224bbb8c5330b40ae561c85e65c3fc05669afd2eb2b026acc40eddc2b099ca0719fde7e9acad7227afbc309ae3840beb4d559d82ffc0fc881c3145776e4334d
7
- data.tar.gz: 4c9595417be360e5b12d35bb6bbcc4f8c36037071027d32af0bdefd513775a4d932198aceeda1f55fdbd2914dce12dea8d92ba8191813eb2f8b32cd8666228c1
6
+ metadata.gz: 90e236478c7c99cfaacc1c31956f1d185a9746c82824cdd59d0ae565e0450311205389dcf5c21a588148e7389eda845d1d1558061875982a68be7f0a6b27cadc
7
+ data.tar.gz: e7ce1711703f946ddfd5731ab3d12542c1f0ba26496421cb0c375baadc56998c5c872ff298770ea6814db44d979c304104873dad7850f97a4531c072cf814cdd
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Store
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/store.png)](http://badge.fury.io/rb/store) [![Build Status](https://api.travis-ci.org/holderbaum/store.png)](https://travis-ci.org/holderbaum/store)
3
+ [![Gem Version](https://badge.fury.io/rb/store.png)](http://badge.fury.io/rb/store)
4
+ [![Build Status](https://api.travis-ci.org/holderbaum/store.png)](https://travis-ci.org/holderbaum/store)
5
+ [![Code Climate](https://codeclimate.com/github/holderbaum/store.png)](https://codeclimate.com/github/holderbaum/store)
4
6
 
5
7
  Implementations for using the Repository- and Data Mapper Pattern in ruby
6
8
 
data/example.rb CHANGED
@@ -221,3 +221,11 @@ repo.save(catalog)
221
221
  p repo.find_catalogs_by_name('test')
222
222
 
223
223
  p repo.find_catalogs_by_name('Catalog 1')
224
+
225
+ # simulate external change
226
+
227
+ items = data_mappers['Catalog'].instance_variable_get(:@items)
228
+ items[1]['name'] = 'Externally updated Catalog'
229
+
230
+ # reload known entity
231
+ p repo.reload(catalog)
@@ -67,6 +67,13 @@ class Store
67
67
  end
68
68
  end
69
69
 
70
+ def reload(entity)
71
+ reference = find_entity_reference(entity)
72
+ raise "Unknown entity #{entity.inspect}" unless reference
73
+ ref = Store::Ref.new(extract_entity_class_name(entity), reference)
74
+ single_load(ref)
75
+ end
76
+
70
77
  def single_load(ref)
71
78
  data_mapper = data_mapper(ref)
72
79
  entity_class = @entity_classes[ref.entity_type]
@@ -15,6 +15,10 @@ class Store
15
15
  true
16
16
  end
17
17
 
18
+ def reload(entity)
19
+ @store.reload(entity)
20
+ end
21
+
18
22
  def save_and_load(entities)
19
23
  refs = @store.save(entities)
20
24
  @store.load(refs)
@@ -1,3 +1,3 @@
1
1
  class Store
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -59,4 +59,13 @@ describe 'Store::Repo' do
59
59
  assert_equal :entities, result
60
60
  end
61
61
 
62
+ it 'delegeates reload to @store' do
63
+ store.expect :reload, :result, [:arg]
64
+
65
+ result = repo.reload(:arg)
66
+
67
+ assert store.verify
68
+ assert_equal :result, result
69
+ end
70
+
62
71
  end
@@ -132,6 +132,28 @@ describe 'store' do
132
132
  assert_match(/no data_mapper .* found/i, error.message)
133
133
  end
134
134
 
135
+ describe 'reload' do
136
+ it 'delegates to load with reference' do
137
+ ref = Store::Ref.new('name', :ref22)
138
+ data_mapper.expect(:insert, ref, [entity_hash])
139
+ store.save(entity)
140
+
141
+ data_mapper.expect(:single_find, {'email' => '1', 'gender' => '2'}, [ref])
142
+ result = store.reload(entity)
143
+
144
+ assert data_mapper.verify
145
+ assert_equal entity_class.new('1', '2'), result
146
+ end
147
+
148
+ it 'raises if reference not known' do
149
+ error = assert_raises RuntimeError do
150
+ store.reload(entity)
151
+ end
152
+
153
+ assert_match(/unknown/i, error.message)
154
+ end
155
+ end
156
+
135
157
  describe 'load' do
136
158
  it 'accepts a ref object and delegates to single_find' do
137
159
  data_mapper.expect(:insert, :ref22, [entity_hash])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Holderbaum