vorpal 0.0.7.rc2 → 0.0.7.rc3

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: 8b6b4c26a538b1aeac920b566ce3b80e0b04e4fe
4
- data.tar.gz: 88d0f3a57930e3a8587d89d085293ac9d032fc58
3
+ metadata.gz: 9f2563f7c44050a5908ff5d2d3d08e9d35a343db
4
+ data.tar.gz: 569a5eb41e1278bb6b28f8e49eab416e4b38cfa5
5
5
  SHA512:
6
- metadata.gz: f0190b9231a1ecce12aec8c62a92345e62ae98470f488401f8e0947ddf37bba7573263a9b78b79635958d85614b9249ab952526542cfe48a081c1d6de179ff3d
7
- data.tar.gz: 32e2963bc4cb79a56de8499fff09b439475f0371d6b4d6f2cfaa8bb87d5b431070965adfcf708e45546db846063418abcabd5e9e64ed8af4054e9c45fbe37be7
6
+ metadata.gz: e45f9c3942c256d2fcda1c360dda4e51da9d777d8381ab7bd0dfa1fcaf6db6901a3699ab4d9110d7f850556c43fc7a345af6406eda03c7748702e69c09a06269
7
+ data.tar.gz: e24ffc7f449a88ad55a9af19cb4a043f389ae34e3788f466b7354a34eda83f3846562d72efda14493ed8995e05bee9a8c5c9d0d21a73e827e4d07210768ab058
data/README.md CHANGED
@@ -123,22 +123,22 @@ module TreeRepository
123
123
  belongs_to :tree
124
124
  end
125
125
  end
126
- @repository = engine.repository_for(Tree)
126
+ @mapper = engine.mapper_for(Tree)
127
127
 
128
128
  def find(tree_id)
129
- @repository.load_one(@repository.db_class.where(id: tree_id).first)
129
+ @mapper.query.where(id: tree_id).load_one
130
130
  end
131
131
 
132
132
  def save(tree)
133
- @repository.persist(tree)
133
+ @mapper.persist(tree)
134
134
  end
135
135
 
136
136
  def destroy(tree)
137
- @repository.destroy(tree)
137
+ @mapper.destroy(tree)
138
138
  end
139
139
 
140
140
  def destroy_by_id(tree_id)
141
- @repository.destroy_by_id(tree_id)
141
+ @mapper.destroy_by_id(tree_id)
142
142
  end
143
143
  end
144
144
  ```
@@ -209,8 +209,7 @@ For example:
209
209
 
210
210
  ```ruby
211
211
  def find_all
212
- ids = @repository.db_class(Tree).pluck(:id) # use an AR query to determine the aggregate ids
213
- @repository.load_all(ids, Tree) # use the repository to load all the aggregates
212
+ @mapper.query.load_all # use the mapper to load all the aggregates
214
213
  end
215
214
  ```
216
215
 
@@ -1,7 +1,7 @@
1
1
  require 'vorpal/identity_map'
2
2
 
3
3
  module Vorpal
4
- class AggregateRepository
4
+ class AggregateMapper
5
5
  # @private
6
6
  def initialize(domain_class, engine)
7
7
  @domain_class = domain_class
@@ -85,7 +85,6 @@ module Vorpal
85
85
  end
86
86
 
87
87
  def query
88
- # db_class.unscoped.extending(ArelQueryMethods.new(self))
89
88
  @engine.query(@domain_class)
90
89
  end
91
90
  end
@@ -6,7 +6,7 @@ module Vorpal
6
6
 
7
7
  # Configures and creates a {Engine} instance.
8
8
  #
9
- # @param options [Hash] Global configuration options for the repository instance.
9
+ # @param options [Hash] Global configuration options for the engine instance.
10
10
  # @option options [Object] :db_driver (Object that will be used to interact with the DB.)
11
11
  # Must be duck-type compatible with {DbDriver}.
12
12
  #
@@ -68,8 +68,8 @@ module Vorpal
68
68
  # Builds a composable query object (e.g. ActiveRecord::Relation) with Vorpal methods mixed in.
69
69
  #
70
70
  # @param class_config [ClassConfig] Config of the entity whose db representations should be returned.
71
- def query(class_config)
72
- class_config.db_class.unscoped.extending(ArelQueryMethods.new(self))
71
+ def query(class_config, aggregate_mapper)
72
+ class_config.db_class.unscoped.extending(ArelQueryMethods.new(aggregate_mapper))
73
73
  end
74
74
 
75
75
  private
@@ -88,30 +88,30 @@ module Vorpal
88
88
  end
89
89
 
90
90
  class ArelQueryMethods < Module
91
- def initialize(repository)
92
- @repository = repository
91
+ def initialize(mapper)
92
+ @mapper = mapper
93
93
  end
94
94
 
95
95
  def extended(descendant)
96
96
  super
97
97
  descendant.extend(Methods)
98
- descendant.vorpal_aggregate_repository = @repository
98
+ descendant.vorpal_aggregate_mapper = @mapper
99
99
  end
100
100
 
101
101
  # Methods in this module will appear on any composable
102
102
  module Methods
103
- attr_writer :vorpal_aggregate_repository
103
+ attr_writer :vorpal_aggregate_mapper
104
104
 
105
- # See {AggregateRepository#load_many}.
105
+ # See {AggregateMapper#load_many}.
106
106
  def load_many
107
107
  db_roots = self.all
108
- @vorpal_aggregate_repository.load_many(db_roots)
108
+ @vorpal_aggregate_mapper.load_many(db_roots)
109
109
  end
110
110
 
111
- # See {AggregateRepository#load_one}.
111
+ # See {AggregateMapper#load_one}.
112
112
  def load_one
113
113
  db_root = self.first
114
- @vorpal_aggregate_repository.load_one(db_root)
114
+ @vorpal_aggregate_mapper.load_one(db_root)
115
115
  end
116
116
  end
117
117
  end
data/lib/vorpal/engine.rb CHANGED
@@ -2,7 +2,7 @@ require 'vorpal/identity_map'
2
2
  require 'vorpal/aggregate_utils'
3
3
  require 'vorpal/db_loader'
4
4
  require 'vorpal/db_driver'
5
- require 'vorpal/aggregate_repository'
5
+ require 'vorpal/aggregate_mapper'
6
6
 
7
7
  module Vorpal
8
8
  class Engine
@@ -12,16 +12,16 @@ module Vorpal
12
12
  @configs = master_config
13
13
  end
14
14
 
15
- # Creates a repository for saving/updating/loading/destroying an aggregate to/from
15
+ # Creates a mapper for saving/updating/loading/destroying an aggregate to/from
16
16
  # the DB. It is possible to use the methods directly on the {Engine}.
17
17
  #
18
18
  # @param domain_class [Class] Class of the root of the aggregate.
19
- # @return [AggregateRepository] Repository suitable for mapping a single aggregate.
20
- def repository_for(domain_class)
21
- AggregateRepository.new(domain_class, self)
19
+ # @return [AggregateMapper] Mapper suitable for mapping a single aggregate.
20
+ def mapper_for(domain_class)
21
+ AggregateMapper.new(domain_class, self)
22
22
  end
23
23
 
24
- # Try to use {AggregateRepository#persist} instead.
24
+ # Try to use {AggregateMapper#persist} instead.
25
25
  def persist(roots)
26
26
  roots = wrap(roots)
27
27
  return roots if roots.empty?
@@ -46,12 +46,12 @@ module Vorpal
46
46
  end
47
47
  end
48
48
 
49
- # Try to use {AggregateRepository#load_one} instead.
49
+ # Try to use {AggregateMapper#load_one} instead.
50
50
  def load_one(db_root, domain_class, identity_map)
51
51
  load_many(Array(db_root), domain_class, identity_map).first
52
52
  end
53
53
 
54
- # Try to use {AggregateRepository#load_many} instead.
54
+ # Try to use {AggregateMapper#load_many} instead.
55
55
  def load_many(db_roots, domain_class, identity_map)
56
56
  raise InvalidAggregateRoot, 'Nil aggregate roots are not allowed.' if db_roots.any?(&:nil?)
57
57
 
@@ -62,7 +62,7 @@ module Vorpal
62
62
  db_roots.map { |db_object| identity_map.get(db_object) }
63
63
  end
64
64
 
65
- # Try to use {AggregateRepository#destroy} instead.
65
+ # Try to use {AggregateMapper#destroy} instead.
66
66
  def destroy(roots)
67
67
  roots = wrap(roots)
68
68
  return roots if roots.empty?
@@ -72,7 +72,7 @@ module Vorpal
72
72
  roots
73
73
  end
74
74
 
75
- # Try to use {AggregateRepository#destroy_by_id} instead.
75
+ # Try to use {AggregateMapper#destroy_by_id} instead.
76
76
  def destroy_by_id(ids, domain_class)
77
77
  ids = wrap(ids)
78
78
  raise InvalidPrimaryKeyValue, 'Nil primary key values are not allowed.' if ids.any?(&:nil?)
@@ -84,13 +84,13 @@ module Vorpal
84
84
  ids
85
85
  end
86
86
 
87
- # Try to use {AggregateRepository#db_class} instead.
87
+ # Try to use {AggregateMapper#db_class} instead.
88
88
  def db_class(domain_class)
89
89
  @configs.config_for(domain_class).db_class
90
90
  end
91
91
 
92
92
  def query(domain_class)
93
- @db_driver.query(@configs.config_for(domain_class))
93
+ @db_driver.query(@configs.config_for(domain_class), mapper_for(domain_class))
94
94
  end
95
95
 
96
96
  private
@@ -1,3 +1,3 @@
1
1
  module Vorpal
2
- VERSION = "0.0.7.rc2"
2
+ VERSION = "0.0.7.rc3"
3
3
  end
data/lib/vorpal.rb CHANGED
@@ -22,7 +22,7 @@ require "vorpal/configuration"
22
22
  # end
23
23
  # end
24
24
  #
25
- # repository = engine.repository_for(Tree)
25
+ # mapper = engine.mapper_for(Tree)
26
26
  # ```
27
27
  module Vorpal
28
28
  extend Vorpal::Configuration
@@ -3,7 +3,7 @@ require 'vorpal'
3
3
  require 'virtus'
4
4
  require 'activerecord-import/base'
5
5
 
6
- describe 'Aggregate Repository' do
6
+ describe 'AggregateMapper' do
7
7
 
8
8
  # for testing polymorphic associations
9
9
  class Bug
@@ -60,20 +60,20 @@ describe 'Aggregate Repository' do
60
60
 
61
61
  describe 'new records' do
62
62
  it 'saves attributes' do
63
- test_repository = configure
63
+ test_mapper = configure
64
64
 
65
65
  tree = Tree.new(name: 'backyard tree')
66
- test_repository.persist(tree)
66
+ test_mapper.persist(tree)
67
67
 
68
68
  tree_db = TreeDB.first
69
69
  expect(tree_db.name).to eq 'backyard tree'
70
70
  end
71
71
 
72
72
  it 'sets the id when first saved' do
73
- test_repository = configure
73
+ test_mapper = configure
74
74
 
75
75
  tree = Tree.new()
76
- test_repository.persist(tree)
76
+ test_mapper.persist(tree)
77
77
 
78
78
  expect(tree.id).to_not be nil
79
79
 
@@ -82,12 +82,12 @@ describe 'Aggregate Repository' do
82
82
  end
83
83
 
84
84
  it 'saves AR::Base objects' do
85
- test_repository = configure
85
+ test_mapper = configure
86
86
 
87
87
  fissure = Fissure.new(length: 21)
88
88
  tree = Tree.new(fissures: [fissure])
89
89
 
90
- test_repository.persist(tree)
90
+ test_mapper.persist(tree)
91
91
 
92
92
  expect(Fissure.first.length).to eq 21
93
93
  end
@@ -96,7 +96,7 @@ describe 'Aggregate Repository' do
96
96
  describe 'on error' do
97
97
  it 'nils ids of new objects' do
98
98
  db_driver = Vorpal::DbDriver.new
99
- test_repository = configure(db_driver: db_driver)
99
+ test_mapper = configure(db_driver: db_driver)
100
100
 
101
101
  tree_db = TreeDB.create!
102
102
 
@@ -106,7 +106,7 @@ describe 'Aggregate Repository' do
106
106
  tree = Tree.new(id: tree_db.id, fissures: [fissure])
107
107
 
108
108
  expect {
109
- test_repository.persist(tree)
109
+ test_mapper.persist(tree)
110
110
  }.to raise_error(Exception)
111
111
 
112
112
  expect(fissure.id).to eq nil
@@ -116,112 +116,112 @@ describe 'Aggregate Repository' do
116
116
 
117
117
  describe 'existing records' do
118
118
  it 'updates attributes' do
119
- test_repository = configure
119
+ test_mapper = configure
120
120
 
121
121
  tree = Tree.new(name: 'little tree')
122
- test_repository.persist(tree)
122
+ test_mapper.persist(tree)
123
123
 
124
124
  tree.name = 'big tree'
125
- test_repository.persist(tree)
125
+ test_mapper.persist(tree)
126
126
 
127
127
  tree_db = TreeDB.first
128
128
  expect(tree_db.name).to eq 'big tree'
129
129
  end
130
130
 
131
131
  it 'does not change the id on update' do
132
- test_repository = configure
132
+ test_mapper = configure
133
133
 
134
134
  tree = Tree.new
135
- test_repository.persist(tree)
135
+ test_mapper.persist(tree)
136
136
 
137
137
  original_id = tree.id
138
138
 
139
139
  tree.name = 'change it'
140
- test_repository.persist(tree)
140
+ test_mapper.persist(tree)
141
141
 
142
142
  expect(tree.id).to eq original_id
143
143
  end
144
144
 
145
145
  it 'does not create additional records' do
146
- test_repository = configure
146
+ test_mapper = configure
147
147
 
148
148
  tree = Tree.new
149
- test_repository.persist(tree)
149
+ test_mapper.persist(tree)
150
150
 
151
151
  tree.name = 'change it'
152
- test_repository.persist(tree)
152
+ test_mapper.persist(tree)
153
153
 
154
154
  expect(TreeDB.count).to eq 1
155
155
  end
156
156
 
157
157
  it 'removes orphans' do
158
- test_repository = configure
158
+ test_mapper = configure
159
159
 
160
160
  tree_db = TreeDB.create!
161
161
  BranchDB.create!(tree_id: tree_db.id)
162
162
 
163
163
  tree = Tree.new(id: tree_db.id, branches: [])
164
164
 
165
- test_repository.persist(tree)
165
+ test_mapper.persist(tree)
166
166
 
167
167
  expect(BranchDB.count).to eq 0
168
168
  end
169
169
 
170
170
  it 'does not remove orphans from unowned associations' do
171
- test_repository = configure_unowned
171
+ test_mapper = configure_unowned
172
172
 
173
173
  tree_db = TreeDB.create!
174
174
  BranchDB.create!(tree_id: tree_db.id)
175
175
 
176
176
  tree = Tree.new(id: tree_db.id, branches: [])
177
177
 
178
- test_repository.persist(tree)
178
+ test_mapper.persist(tree)
179
179
 
180
180
  expect(BranchDB.count).to eq 1
181
181
  end
182
182
  end
183
183
 
184
184
  it 'copies attributes to domain' do
185
- test_repository = configure
185
+ test_mapper = configure
186
186
 
187
187
  tree_db = TreeDB.create! name: 'tree name'
188
- tree = test_repository.load_one(tree_db)
188
+ tree = test_mapper.load_one(tree_db)
189
189
 
190
190
  expect(tree.id).to eq tree_db.id
191
191
  expect(tree.name).to eq 'tree name'
192
192
  end
193
193
 
194
194
  it 'hydrates ActiveRecord::Base associations' do
195
- test_repository = configure
195
+ test_mapper = configure
196
196
 
197
197
  tree_db = TreeDB.create!
198
198
  Fissure.create! length: 21, tree_id: tree_db.id
199
199
 
200
- tree = test_repository.load_one(tree_db)
200
+ tree = test_mapper.load_one(tree_db)
201
201
 
202
202
  expect(tree.fissures.first.length).to eq 21
203
203
  end
204
204
 
205
205
  describe 'cycles' do
206
206
  it 'persists' do
207
- test_repository = configure_with_cycle
207
+ test_mapper = configure_with_cycle
208
208
 
209
209
  tree = Tree.new
210
210
  long_branch = Branch.new(length: 100, tree: tree)
211
211
  tree.branches << long_branch
212
212
 
213
- test_repository.persist(tree)
213
+ test_mapper.persist(tree)
214
214
 
215
215
  expect(TreeDB.count).to eq 1
216
216
  end
217
217
 
218
218
  it 'hydrates' do
219
- test_repository = configure_with_cycle
219
+ test_mapper = configure_with_cycle
220
220
 
221
221
  tree_db = TreeDB.create!
222
222
  BranchDB.create!(length: 50, tree_id: tree_db.id)
223
223
 
224
- tree = test_repository.load_one(tree_db)
224
+ tree = test_mapper.load_one(tree_db)
225
225
 
226
226
  expect(tree).to be tree.branches.first.tree
227
227
  end
@@ -229,7 +229,7 @@ describe 'Aggregate Repository' do
229
229
 
230
230
  describe 'recursive associations' do
231
231
  it 'persists' do
232
- test_repository = configure_recursive
232
+ test_mapper = configure_recursive
233
233
 
234
234
  tree = Tree.new
235
235
  long_branch = Branch.new(length: 100, tree: tree)
@@ -237,19 +237,19 @@ describe 'Aggregate Repository' do
237
237
  short_branch = Branch.new(length: 50, tree: tree)
238
238
  long_branch.branches << short_branch
239
239
 
240
- test_repository.persist(tree)
240
+ test_mapper.persist(tree)
241
241
 
242
242
  expect(BranchDB.count).to eq 2
243
243
  end
244
244
 
245
245
  it 'hydrates' do
246
- test_repository = configure_recursive
246
+ test_mapper = configure_recursive
247
247
 
248
248
  tree_db = TreeDB.create!
249
249
  long_branch = BranchDB.create!(length: 100, tree_id: tree_db.id)
250
250
  BranchDB.create!(length: 50, branch_id: long_branch.id)
251
251
 
252
- tree = test_repository.load_one(tree_db)
252
+ tree = test_mapper.load_one(tree_db)
253
253
 
254
254
  expect(tree.branches.first.branches.first.length).to eq 50
255
255
  end
@@ -257,68 +257,68 @@ describe 'Aggregate Repository' do
257
257
 
258
258
  describe 'belongs_to associations' do
259
259
  it 'saves attributes' do
260
- test_repository = configure
260
+ test_mapper = configure
261
261
  trunk = Trunk.new(length: 12)
262
262
  tree = Tree.new(trunk: trunk)
263
263
 
264
- test_repository.persist(tree)
264
+ test_mapper.persist(tree)
265
265
 
266
266
  trunk_db = TrunkDB.first
267
267
  expect(trunk_db.length).to eq 12
268
268
  end
269
269
 
270
270
  it 'saves foreign keys' do
271
- test_repository = configure
271
+ test_mapper = configure
272
272
  trunk = Trunk.new
273
273
  tree = Tree.new(trunk: trunk)
274
274
 
275
- test_repository.persist(tree)
275
+ test_mapper.persist(tree)
276
276
 
277
277
  tree_db = TreeDB.first
278
278
  expect(tree_db.trunk_id).to eq trunk.id
279
279
  end
280
280
 
281
281
  it 'updating does not create additional rows' do
282
- test_repository = configure
282
+ test_mapper = configure
283
283
  trunk = Trunk.new
284
284
  tree = Tree.new(trunk: trunk)
285
285
 
286
- test_repository.persist(tree)
286
+ test_mapper.persist(tree)
287
287
 
288
288
  trunk.length = 21
289
289
 
290
- expect{ test_repository.persist(tree) }.to_not change{ TrunkDB.count }
290
+ expect{ test_mapper.persist(tree) }.to_not change{ TrunkDB.count }
291
291
  end
292
292
 
293
293
  it 'only saves entities that are owned' do
294
- test_repository = configure_unowned
294
+ test_mapper = configure_unowned
295
295
 
296
296
  trunk = Trunk.new
297
297
  tree = Tree.new(trunk: trunk)
298
298
 
299
- test_repository.persist(tree)
299
+ test_mapper.persist(tree)
300
300
 
301
301
  expect(TrunkDB.count).to eq 0
302
302
  end
303
303
 
304
304
  it 'hydrates' do
305
- test_repository = configure
305
+ test_mapper = configure
306
306
  trunk_db = TrunkDB.create!(length: 21)
307
307
  tree_db = TreeDB.create!(trunk_id: trunk_db.id)
308
308
 
309
- new_tree = test_repository.load_one(tree_db)
309
+ new_tree = test_mapper.load_one(tree_db)
310
310
  expect(new_tree.trunk.length).to eq 21
311
311
  end
312
312
  end
313
313
 
314
314
  describe 'has_many associations' do
315
315
  it 'saves' do
316
- test_repository = configure
316
+ test_mapper = configure
317
317
  tree = Tree.new
318
318
  tree.branches << Branch.new(length: 100)
319
319
  tree.branches << Branch.new(length: 3)
320
320
 
321
- test_repository.persist(tree)
321
+ test_mapper.persist(tree)
322
322
 
323
323
  branches = BranchDB.all
324
324
  expect(branches.size).to eq 2
@@ -327,51 +327,51 @@ describe 'Aggregate Repository' do
327
327
  end
328
328
 
329
329
  it 'saves foreign keys' do
330
- test_repository = configure
330
+ test_mapper = configure
331
331
  tree = Tree.new
332
332
  tree.branches << Branch.new(length: 100)
333
333
 
334
- test_repository.persist(tree)
334
+ test_mapper.persist(tree)
335
335
 
336
336
  branches = BranchDB.all
337
337
  expect(branches.first.tree_id).to eq tree.id
338
338
  end
339
339
 
340
340
  it 'updates' do
341
- test_repository = configure
341
+ test_mapper = configure
342
342
  tree = Tree.new
343
343
  long_branch = Branch.new(length: 100)
344
344
  tree.branches << long_branch
345
345
 
346
- test_repository.persist(tree)
346
+ test_mapper.persist(tree)
347
347
 
348
348
  long_branch.length = 120
349
349
 
350
- test_repository.persist(tree)
350
+ test_mapper.persist(tree)
351
351
 
352
352
  branches = BranchDB.all
353
353
  expect(branches.first.length).to eq 120
354
354
  end
355
355
 
356
356
  it 'only saves entities that are owned' do
357
- test_repository = configure_unowned
357
+ test_mapper = configure_unowned
358
358
 
359
359
  tree = Tree.new
360
360
  long_branch = Branch.new(length: 100)
361
361
  tree.branches << long_branch
362
362
 
363
- test_repository.persist(tree)
363
+ test_mapper.persist(tree)
364
364
 
365
365
  expect(BranchDB.count).to eq 0
366
366
  end
367
367
 
368
368
  it 'hydrates' do
369
- test_repository = configure
369
+ test_mapper = configure
370
370
 
371
371
  tree_db = TreeDB.create!
372
372
  BranchDB.create!(length: 50, tree_id: tree_db.id)
373
373
 
374
- tree = test_repository.load_one(tree_db)
374
+ tree = test_mapper.load_one(tree_db)
375
375
 
376
376
  expect(tree.branches.first.length).to eq 50
377
377
  end
@@ -379,42 +379,42 @@ describe 'Aggregate Repository' do
379
379
 
380
380
  describe 'has_one associations' do
381
381
  it 'saves' do
382
- test_repository = configure_has_one
382
+ test_mapper = configure_has_one
383
383
  tree = Tree.new(name: 'big tree')
384
384
  trunk = Trunk.new(tree: tree)
385
385
 
386
- test_repository.persist(trunk)
386
+ test_mapper.persist(trunk)
387
387
 
388
388
  expect(TreeDB.first.name).to eq 'big tree'
389
389
  end
390
390
 
391
391
  it 'saves foreign keys' do
392
- test_repository = configure_has_one
392
+ test_mapper = configure_has_one
393
393
  tree = Tree.new(name: 'big tree')
394
394
  trunk = Trunk.new(tree: tree)
395
395
 
396
- test_repository.persist(trunk)
396
+ test_mapper.persist(trunk)
397
397
 
398
398
  expect(TreeDB.first.trunk_id).to eq trunk.id
399
399
  end
400
400
 
401
401
  it 'only saves entities that are owned' do
402
- test_repository = configure_unowned_has_one
402
+ test_mapper = configure_unowned_has_one
403
403
  tree = Tree.new
404
404
  trunk = Trunk.new(tree: tree)
405
405
 
406
- test_repository.persist(trunk)
406
+ test_mapper.persist(trunk)
407
407
 
408
408
  expect(TreeDB.count).to eq 0
409
409
  end
410
410
 
411
411
  it 'hydrates' do
412
- test_repository = configure_has_one
412
+ test_mapper = configure_has_one
413
413
 
414
414
  trunk_db = TrunkDB.create!
415
415
  TreeDB.create!(name: 'big tree', trunk_id: trunk_db.id)
416
416
 
417
- trunk = test_repository.load_one(trunk_db)
417
+ trunk = test_mapper.load_one(trunk_db)
418
418
 
419
419
  expect(trunk.tree.name).to eq 'big tree'
420
420
  end
@@ -422,7 +422,7 @@ describe 'Aggregate Repository' do
422
422
 
423
423
  describe 'polymorphic associations' do
424
424
  it 'saves with has_manys' do
425
- test_repository = configure_polymorphic_has_many
425
+ test_mapper = configure_polymorphic_has_many
426
426
  trunk = Trunk.new
427
427
  branch = Branch.new
428
428
  tree = Tree.new(trunk: trunk, branches: [branch])
@@ -432,50 +432,50 @@ describe 'Aggregate Repository' do
432
432
  branch_bug = Bug.new
433
433
  branch.bugs << branch_bug
434
434
 
435
- test_repository.persist(tree)
435
+ test_mapper.persist(tree)
436
436
 
437
437
  expect(BugDB.find(trunk_bug.id).lives_on_type).to eq Trunk.name
438
438
  expect(BugDB.find(branch_bug.id).lives_on_type).to eq Branch.name
439
439
  end
440
440
 
441
441
  it 'restores with has_manys' do
442
- test_repository = configure_polymorphic_has_many
442
+ test_mapper = configure_polymorphic_has_many
443
443
 
444
444
  trunk_db = TrunkDB.create!
445
445
  tree_db = TreeDB.create!(trunk_id: trunk_db.id)
446
446
  BugDB.create!(name: 'trunk bug', lives_on_id: trunk_db.id, lives_on_type: Trunk.name)
447
447
  BugDB.create!(name: 'not a trunk bug!', lives_on_id: trunk_db.id, lives_on_type: 'some other table')
448
448
 
449
- tree = test_repository.load_one(tree_db)
449
+ tree = test_mapper.load_one(tree_db)
450
450
 
451
451
  expect(tree.trunk.bugs.map(&:name)).to eq ['trunk bug']
452
452
  end
453
453
 
454
454
  it 'saves with belongs_tos' do
455
- test_repository = configure_polymorphic_belongs_to
455
+ test_mapper = configure_polymorphic_belongs_to
456
456
 
457
457
  trunk_bug = Bug.new(lives_on: Trunk.new)
458
458
  branch_bug = Bug.new(lives_on: Branch.new)
459
459
 
460
- test_repository.persist([trunk_bug, branch_bug])
460
+ test_mapper.persist([trunk_bug, branch_bug])
461
461
 
462
462
  expect(BugDB.find(trunk_bug.id).lives_on_type).to eq Trunk.name
463
463
  expect(BugDB.find(branch_bug.id).lives_on_type).to eq Branch.name
464
464
  end
465
465
 
466
466
  it 'saves associations to unowned entities via belongs_to' do
467
- test_repository = configure_unowned_polymorphic_belongs_to
467
+ test_mapper = configure_unowned_polymorphic_belongs_to
468
468
  trunk = Trunk.new
469
469
 
470
470
  trunk_bug = Bug.new(lives_on: trunk)
471
471
 
472
- test_repository.persist(trunk_bug)
472
+ test_mapper.persist(trunk_bug)
473
473
 
474
474
  expect(BugDB.find(trunk_bug.id).lives_on_type).to eq Trunk.name
475
475
  end
476
476
 
477
477
  it 'restores with belongs_tos' do
478
- test_repository = configure_polymorphic_belongs_to
478
+ test_mapper = configure_polymorphic_belongs_to
479
479
 
480
480
  # makes sure that we are using the fk_type to discriminate against
481
481
  # two entities with the same primary key value
@@ -488,19 +488,19 @@ describe 'Aggregate Repository' do
488
488
  branch_db.save!
489
489
  branch_bug_db = BugDB.create!(lives_on_id: branch_db.id, lives_on_type: Branch.name)
490
490
 
491
- trunk_bug, branch_bug = test_repository.load_many([trunk_bug_db, branch_bug_db])
491
+ trunk_bug, branch_bug = test_mapper.load_many([trunk_bug_db, branch_bug_db])
492
492
 
493
493
  expect(trunk_bug.lives_on.length).to eq 99
494
494
  expect(branch_bug.lives_on.length).to eq 5
495
495
  end
496
496
 
497
497
  it 'restores active record objects' do
498
- test_repository = configure_ar_polymorphic_belongs_to
498
+ test_mapper = configure_ar_polymorphic_belongs_to
499
499
 
500
500
  swamp = Swamp.create!
501
501
  tree_db = TreeDB.create!(environment_id: swamp.id, environment_type: Swamp.name)
502
502
 
503
- tree = test_repository.load_one(tree_db)
503
+ tree = test_mapper.load_one(tree_db)
504
504
 
505
505
  expect(tree.environment).to eq swamp
506
506
  end
@@ -508,23 +508,23 @@ describe 'Aggregate Repository' do
508
508
 
509
509
  describe 'arel' do
510
510
  it 'loads many' do
511
- test_repository = configure
511
+ test_mapper = configure
512
512
 
513
513
  TreeDB.create!
514
514
  tree_db = TreeDB.create!
515
515
 
516
- trees = test_repository.query.where(id: tree_db.id).load_many
516
+ trees = test_mapper.query.where(id: tree_db.id).load_many
517
517
 
518
518
  expect(trees.map(&:id)).to eq [tree_db.id]
519
519
  end
520
520
 
521
521
  it 'loads one' do
522
- test_repository = configure
522
+ test_mapper = configure
523
523
 
524
524
  TreeDB.create!
525
525
  tree_db = TreeDB.create!
526
526
 
527
- trees = test_repository.query.where(id: tree_db.id).load_one
527
+ trees = test_mapper.query.where(id: tree_db.id).load_one
528
528
 
529
529
  expect(trees.id).to eq tree_db.id
530
530
  end
@@ -532,24 +532,24 @@ describe 'Aggregate Repository' do
532
532
 
533
533
  describe 'load_many' do
534
534
  it 'maps given db objects' do
535
- test_repository = configure
535
+ test_mapper = configure
536
536
 
537
537
  TreeDB.create!
538
538
  tree_db = TreeDB.create!
539
539
 
540
- trees = test_repository.load_many([tree_db])
540
+ trees = test_mapper.load_many([tree_db])
541
541
 
542
542
  expect(trees.map(&:id)).to eq [tree_db.id]
543
543
  end
544
544
 
545
545
  it 'only returns roots' do
546
- test_repository = configure
546
+ test_mapper = configure
547
547
 
548
548
  TreeDB.create!
549
549
  tree_db = TreeDB.create!
550
550
  BranchDB.create!(tree_id: tree_db.id)
551
551
 
552
- trees = test_repository.load_many([tree_db])
552
+ trees = test_mapper.load_many([tree_db])
553
553
 
554
554
  expect(trees.map(&:id)).to eq [tree_db.id]
555
555
  end
@@ -557,66 +557,66 @@ describe 'Aggregate Repository' do
557
557
 
558
558
  describe 'destroy' do
559
559
  it 'removes the entity from the database' do
560
- test_repository = configure
560
+ test_mapper = configure
561
561
 
562
562
  tree_db = TreeDB.create!
563
563
 
564
- test_repository.destroy([Tree.new(id: tree_db.id)])
564
+ test_mapper.destroy([Tree.new(id: tree_db.id)])
565
565
 
566
566
  expect(TreeDB.count).to eq 0
567
567
  end
568
568
 
569
569
  it 'removes has many children from the database' do
570
- test_repository = configure
570
+ test_mapper = configure
571
571
 
572
572
  tree_db = TreeDB.create!
573
573
  BranchDB.create!(tree_id: tree_db.id)
574
574
 
575
- test_repository.destroy(Tree.new(id: tree_db.id))
575
+ test_mapper.destroy(Tree.new(id: tree_db.id))
576
576
 
577
577
  expect(BranchDB.count).to eq 0
578
578
  end
579
579
 
580
580
  it 'removes belongs to children from the database' do
581
- test_repository = configure
581
+ test_mapper = configure
582
582
 
583
583
  trunk_db = TrunkDB.create!
584
584
  tree_db = TreeDB.create!(trunk_id: trunk_db.id)
585
585
 
586
- test_repository.destroy(Tree.new(id: tree_db.id))
586
+ test_mapper.destroy(Tree.new(id: tree_db.id))
587
587
 
588
588
  expect(TrunkDB.count).to eq 0
589
589
  end
590
590
 
591
591
  it 'removes AR children from the database' do
592
- test_repository = configure
592
+ test_mapper = configure
593
593
 
594
594
  tree_db = TreeDB.create!
595
595
  Fissure.create!(tree_id: tree_db.id)
596
596
 
597
- test_repository.destroy(Tree.new(id: tree_db.id))
597
+ test_mapper.destroy(Tree.new(id: tree_db.id))
598
598
 
599
599
  expect(Fissure.count).to eq 0
600
600
  end
601
601
 
602
602
  it 'leaves unowned belongs to children in the database' do
603
- test_repository = configure_unowned
603
+ test_mapper = configure_unowned
604
604
 
605
605
  trunk_db = TrunkDB.create!
606
606
  tree_db = TreeDB.create!(trunk_id: trunk_db.id)
607
607
 
608
- test_repository.destroy(Tree.new(id: tree_db.id))
608
+ test_mapper.destroy(Tree.new(id: tree_db.id))
609
609
 
610
610
  expect(TrunkDB.count).to eq 1
611
611
  end
612
612
 
613
613
  it 'leaves unowned has many children in the database' do
614
- test_repository = configure_unowned
614
+ test_mapper = configure_unowned
615
615
 
616
616
  tree_db = TreeDB.create!
617
617
  BranchDB.create!(tree_id: tree_db.id)
618
618
 
619
- test_repository.destroy(Tree.new(id: tree_db.id))
619
+ test_mapper.destroy(Tree.new(id: tree_db.id))
620
620
 
621
621
  expect(BranchDB.count).to eq 1
622
622
  end
@@ -624,11 +624,11 @@ describe 'Aggregate Repository' do
624
624
 
625
625
  describe 'destroy_by_id' do
626
626
  it 'removes the entity from the database' do
627
- test_repository = configure
627
+ test_mapper = configure
628
628
 
629
629
  tree_db = TreeDB.create!
630
630
 
631
- test_repository.destroy_by_id([tree_db.id])
631
+ test_mapper.destroy_by_id([tree_db.id])
632
632
 
633
633
  expect(TreeDB.count).to eq 0
634
634
  end
@@ -636,97 +636,97 @@ describe 'Aggregate Repository' do
636
636
 
637
637
  describe 'non-existent values' do
638
638
  it 'load_many returns an empty array when given an empty array' do
639
- test_repository = configure
639
+ test_mapper = configure
640
640
 
641
- results = test_repository.load_many([])
641
+ results = test_mapper.load_many([])
642
642
  expect(results).to eq []
643
643
  end
644
644
 
645
645
  it 'load_many throws an exception when given a nil db_object' do
646
- test_repository = configure
646
+ test_mapper = configure
647
647
 
648
648
  expect {
649
- test_repository.load_many([nil])
649
+ test_mapper.load_many([nil])
650
650
  }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
651
651
  end
652
652
 
653
653
  it 'load_one returns nil when given nil' do
654
- test_repository = configure
654
+ test_mapper = configure
655
655
 
656
- result = test_repository.load_one(nil)
656
+ result = test_mapper.load_one(nil)
657
657
  expect(result).to eq nil
658
658
  end
659
659
 
660
660
  it 'persist ignores empty arrays' do
661
- test_repository = configure
661
+ test_mapper = configure
662
662
 
663
- results = test_repository.persist([])
663
+ results = test_mapper.persist([])
664
664
  expect(results).to eq []
665
665
  end
666
666
 
667
667
  it 'persist throws an exception when given a collection with a nil root' do
668
- test_repository = configure
668
+ test_mapper = configure
669
669
  expect {
670
- test_repository.persist([nil])
670
+ test_mapper.persist([nil])
671
671
  }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
672
672
  end
673
673
 
674
674
  it 'persist throws an exception when given a nil root' do
675
- test_repository = configure
675
+ test_mapper = configure
676
676
  expect {
677
- test_repository.persist(nil)
677
+ test_mapper.persist(nil)
678
678
  }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
679
679
  end
680
680
 
681
681
  it 'destroy ignores empty arrays' do
682
- test_repository = configure
682
+ test_mapper = configure
683
683
 
684
- results = test_repository.destroy([])
684
+ results = test_mapper.destroy([])
685
685
  expect(results).to eq []
686
686
  end
687
687
 
688
688
  it 'destroy throws an exception when given a nil root' do
689
- test_repository = configure
689
+ test_mapper = configure
690
690
 
691
691
  expect {
692
- test_repository.destroy(nil)
692
+ test_mapper.destroy(nil)
693
693
  }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
694
694
  end
695
695
 
696
696
  it 'destroy throws an exception when given a collection with a nil root' do
697
- test_repository = configure
697
+ test_mapper = configure
698
698
 
699
699
  expect {
700
- test_repository.destroy([nil])
700
+ test_mapper.destroy([nil])
701
701
  }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
702
702
  end
703
703
 
704
704
  it 'destroy_by_id ignores empty arrays' do
705
- test_repository = configure
705
+ test_mapper = configure
706
706
 
707
- results = test_repository.destroy_by_id([])
707
+ results = test_mapper.destroy_by_id([])
708
708
  expect(results).to eq []
709
709
  end
710
710
 
711
711
  it 'destroy_by_id ignores ids that do not exist' do
712
- test_repository = configure
712
+ test_mapper = configure
713
713
 
714
- test_repository.destroy_by_id([99])
714
+ test_mapper.destroy_by_id([99])
715
715
  end
716
716
 
717
717
  it 'destroy_by_id throws an exception when given a collection with a nil id' do
718
- test_repository = configure
718
+ test_mapper = configure
719
719
 
720
720
  expect {
721
- test_repository.destroy_by_id([nil])
721
+ test_mapper.destroy_by_id([nil])
722
722
  }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
723
723
  end
724
724
 
725
725
  it 'destroy_by_id throws an exception when given a nil id' do
726
- test_repository = configure
726
+ test_mapper = configure
727
727
 
728
728
  expect {
729
- test_repository.destroy_by_id(nil)
729
+ test_mapper.destroy_by_id(nil)
730
730
  }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
731
731
  end
732
732
  end
@@ -755,7 +755,7 @@ private
755
755
  attributes :name
756
756
  end
757
757
  end
758
- engine.repository_for(Tree)
758
+ engine.mapper_for(Tree)
759
759
  end
760
760
 
761
761
  def configure_polymorphic_belongs_to
@@ -773,7 +773,7 @@ private
773
773
  attributes :length
774
774
  end
775
775
  end
776
- engine.repository_for(Bug)
776
+ engine.mapper_for(Bug)
777
777
  end
778
778
 
779
779
  def configure_ar_polymorphic_belongs_to
@@ -785,7 +785,7 @@ private
785
785
 
786
786
  map Swamp, to: Swamp
787
787
  end
788
- engine.repository_for(Tree)
788
+ engine.mapper_for(Tree)
789
789
  end
790
790
 
791
791
  def configure_unowned_polymorphic_belongs_to
@@ -803,7 +803,7 @@ private
803
803
  attributes :length
804
804
  end
805
805
  end
806
- engine.repository_for(Bug)
806
+ engine.mapper_for(Bug)
807
807
  end
808
808
 
809
809
  def configure_unowned
@@ -822,7 +822,7 @@ private
822
822
  attributes :length
823
823
  end
824
824
  end
825
- engine.repository_for(Tree)
825
+ engine.mapper_for(Tree)
826
826
  end
827
827
 
828
828
  def configure_recursive
@@ -837,7 +837,7 @@ private
837
837
  has_many :branches
838
838
  end
839
839
  end
840
- engine.repository_for(Tree)
840
+ engine.mapper_for(Tree)
841
841
  end
842
842
 
843
843
  def configure_with_cycle
@@ -852,7 +852,7 @@ private
852
852
  has_many :branches
853
853
  end
854
854
  end
855
- engine.repository_for(Tree)
855
+ engine.mapper_for(Tree)
856
856
  end
857
857
 
858
858
  def configure(options={})
@@ -874,7 +874,7 @@ private
874
874
 
875
875
  map Fissure, to: Fissure
876
876
  end
877
- engine.repository_for(Tree)
877
+ engine.mapper_for(Tree)
878
878
  end
879
879
 
880
880
  def configure_has_one
@@ -888,7 +888,7 @@ private
888
888
  attributes :name
889
889
  end
890
890
  end
891
- engine.repository_for(Trunk)
891
+ engine.mapper_for(Trunk)
892
892
  end
893
893
 
894
894
  def configure_unowned_has_one
@@ -902,6 +902,6 @@ private
902
902
  attributes :name
903
903
  end
904
904
  end
905
- engine.repository_for(Trunk)
905
+ engine.mapper_for(Trunk)
906
906
  end
907
907
  end
@@ -74,7 +74,7 @@ describe 'performance' do
74
74
  TrunkDB = defineAr('trunks_perf')
75
75
  end
76
76
 
77
- let(:test_repository) { build_repository }
77
+ let(:test_mapper) { build_mapper }
78
78
 
79
79
  # Vorpal 0.0.5:
80
80
  # user system total real
@@ -92,10 +92,10 @@ describe 'performance' do
92
92
  it 'benchmarks all operations' do
93
93
  trees = build_trees(1000)
94
94
  Benchmark.bm(7) do |x|
95
- x.report('create') { test_repository.persist(trees) }
96
- x.report('update') { test_repository.persist(trees) }
97
- x.report('load') { test_repository.load_many(TreeDB.where(id: trees.map(&:id)).all) }
98
- x.report('destroy') { test_repository.destroy(trees) }
95
+ x.report('create') { test_mapper.persist(trees) }
96
+ x.report('update') { test_mapper.persist(trees) }
97
+ x.report('load') { test_mapper.load_many(TreeDB.where(id: trees.map(&:id)).all) }
98
+ x.report('destroy') { test_mapper.destroy(trees) }
99
99
  end
100
100
  end
101
101
 
@@ -104,39 +104,39 @@ describe 'performance' do
104
104
 
105
105
  puts 'starting persistence benchmark'
106
106
  puts Benchmark.measure {
107
- test_repository.persist(trees)
107
+ test_mapper.persist(trees)
108
108
  }
109
109
  end
110
110
 
111
111
  it 'updates aggregates quickly' do
112
112
  trees = build_trees(1000)
113
113
 
114
- test_repository.persist(trees)
114
+ test_mapper.persist(trees)
115
115
 
116
116
  puts 'starting update benchmark'
117
117
  puts Benchmark.measure {
118
- test_repository.persist(trees)
118
+ test_mapper.persist(trees)
119
119
  }
120
120
  end
121
121
 
122
122
  it 'loads aggregates quickly' do
123
123
  trees = build_trees(1000)
124
- test_repository.persist(trees)
124
+ test_mapper.persist(trees)
125
125
  ids = trees.map(&:id)
126
126
 
127
127
  puts 'starting loading benchmark'
128
128
  puts Benchmark.measure {
129
- test_repository.load_many(TreeDB.where(id: ids).all)
129
+ test_mapper.load_many(TreeDB.where(id: ids).all)
130
130
  }
131
131
  end
132
132
 
133
133
  it 'destroys aggregates quickly' do
134
134
  trees = build_trees(1000)
135
- test_repository.persist(trees)
135
+ test_mapper.persist(trees)
136
136
 
137
137
  puts 'starting destruction benchmark'
138
138
  puts Benchmark.measure {
139
- test_repository.destroy(trees)
139
+ test_mapper.destroy(trees)
140
140
  }
141
141
  end
142
142
 
@@ -162,7 +162,7 @@ describe 'performance' do
162
162
  bug_home.bugs = [bug]
163
163
  end
164
164
 
165
- def build_repository
165
+ def build_mapper
166
166
  engine = Vorpal.define do
167
167
  map Tree do
168
168
  attributes :name
@@ -188,6 +188,6 @@ describe 'performance' do
188
188
  belongs_to :lives_on, fk: :lives_on_id, fk_type: :lives_on_type, child_classes: [Trunk, Branch]
189
189
  end
190
190
  end
191
- engine.repository_for(Tree)
191
+ engine.mapper_for(Tree)
192
192
  end
193
193
  end
@@ -65,7 +65,7 @@ describe Vorpal::DbLoader do
65
65
  # p loaded_objects.all_objects
66
66
  # # expect(loaded_objects.all_objects.size).to eq(2)
67
67
  #
68
- # repo = Vorpal::AggregateRepository.new(driver, master_config)
68
+ # repo = Vorpal::AggregateMapper.new(driver, master_config)
69
69
  # post = repo.load(post_db.id, Post)
70
70
  # p post
71
71
  # expect(post.comments.size).to eq(1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vorpal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.rc2
4
+ version: 0.0.7.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Kirby
@@ -152,7 +152,7 @@ files:
152
152
  - README.md
153
153
  - Rakefile
154
154
  - lib/vorpal.rb
155
- - lib/vorpal/aggregate_repository.rb
155
+ - lib/vorpal/aggregate_mapper.rb
156
156
  - lib/vorpal/aggregate_traversal.rb
157
157
  - lib/vorpal/aggregate_utils.rb
158
158
  - lib/vorpal/config_builder.rb
@@ -169,7 +169,7 @@ files:
169
169
  - spec/helpers/db_helpers.rb
170
170
  - spec/integration_spec_helper.rb
171
171
  - spec/unit_spec_helper.rb
172
- - spec/vorpal/acceptance/aggregate_repository_spec.rb
172
+ - spec/vorpal/acceptance/aggregate_mapper_spec.rb
173
173
  - spec/vorpal/performance/performance_spec.rb
174
174
  - spec/vorpal/unit/config_builder_spec.rb
175
175
  - spec/vorpal/unit/configs_spec.rb
@@ -205,7 +205,7 @@ test_files:
205
205
  - spec/helpers/db_helpers.rb
206
206
  - spec/integration_spec_helper.rb
207
207
  - spec/unit_spec_helper.rb
208
- - spec/vorpal/acceptance/aggregate_repository_spec.rb
208
+ - spec/vorpal/acceptance/aggregate_mapper_spec.rb
209
209
  - spec/vorpal/performance/performance_spec.rb
210
210
  - spec/vorpal/unit/config_builder_spec.rb
211
211
  - spec/vorpal/unit/configs_spec.rb