feat(fsrepo): integrate datastore component into FSRepo
"for each desired change, make the change easy (warning: this may be hard), then make the easy change" - Kent Beck https://twitter.com/KentBeck/status/250733358307500032 http://martinfowler.com/articles/preparatory-refactoring-example.html cc @jbenet @whyrusleeping
Brian Tiger Chow committed
Jan 14, 2015 at 08:37 UTC
ece9ed093314516c810de0f3e3c4a74d437eeba6
1 file changed
+23
-8
repo/fsrepo/fsrepo.go
+23
-8
@@ -48,10 +48,12 @@ type FSRepo struct {
48
state state
49
// path is the file-system path
50
path string
51
- // config is loaded when FSRepo is opened and kept up to date when the
52
- // FSRepo is modified.
51
+ // configComponent is loaded when FSRepo is opened and kept up to date when
52
+ // the FSRepo is modified.
53
// TODO test
54
configComponent component.ConfigComponent
55
+ // TODO test
56
+ datastoreComponent component.DatastoreComponent
57
}
58
59
type componentBuilder struct {
@@ -302,7 +304,7 @@ func (r *FSRepo) transitionToClosed() error {
304
func (r *FSRepo) components() []component.Component {
305
return []component.Component{
306
&r.configComponent,
305
- // TODO add datastore
307
+ &r.datastoreComponent,
308
}
309
}
310
@@ -314,16 +316,29 @@ func componentBuilders() []componentBuilder {
316
Init: component.InitConfigComponent,
317
IsInitialized: component.ConfigComponentIsInitialized,
318
OpenHandler: func(r *FSRepo) error {
317
- cc := component.ConfigComponent{}
318
- cc.SetPath(r.path)
319
- if err := cc.Open(); err != nil {
319
+ c := component.ConfigComponent{}
320
+ c.SetPath(r.path)
321
+ if err := c.Open(); err != nil {
322
return err
323
}
322
- r.configComponent = cc
324
+ r.configComponent = c
325
return nil
326
},
327
},
328
327
- // TODO add datastore builder
329
+ // DatastoreComponent
330
+ componentBuilder{
331
+ Init: component.InitDatastoreComponent,
332
+ IsInitialized: component.DatastoreComponentIsInitialized,
333
+ OpenHandler: func(r *FSRepo) error {
334
+ c := component.DatastoreComponent{}
335
+ c.SetPath(r.path)
336
+ if err := c.Open(); err != nil {
337
+ return err
338
+ }
339
+ r.datastoreComponent = c
340
+ return nil
341
+ },
342
+ },
343
}
344
}