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 +4 -4
- data/README.md +3 -1
- data/example.rb +8 -0
- data/lib/store.rb +7 -0
- data/lib/store/repo.rb +4 -0
- data/lib/store/version.rb +1 -1
- data/spec/store_repo_spec.rb +9 -0
- data/spec/store_spec.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b8b967c6d3ba58a8051a867938a7b4d27bfafb0
|
4
|
+
data.tar.gz: de319d311003addd0b4ba4d23a49b2cf6d1bbad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
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)
|
data/lib/store.rb
CHANGED
@@ -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]
|
data/lib/store/repo.rb
CHANGED
data/lib/store/version.rb
CHANGED
data/spec/store_repo_spec.rb
CHANGED
@@ -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
|
data/spec/store_spec.rb
CHANGED
@@ -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])
|