Commit ece9ed09 authored by Brian Tiger Chow's avatar Brian Tiger Chow

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
parent 4ba4ee3a
......@@ -48,10 +48,12 @@ type FSRepo struct {
state state
// path is the file-system path
path string
// config is loaded when FSRepo is opened and kept up to date when the
// FSRepo is modified.
// configComponent is loaded when FSRepo is opened and kept up to date when
// the FSRepo is modified.
// TODO test
configComponent component.ConfigComponent
// TODO test
datastoreComponent component.DatastoreComponent
}
type componentBuilder struct {
......@@ -302,7 +304,7 @@ func (r *FSRepo) transitionToClosed() error {
func (r *FSRepo) components() []component.Component {
return []component.Component{
&r.configComponent,
// TODO add datastore
&r.datastoreComponent,
}
}
......@@ -314,16 +316,29 @@ func componentBuilders() []componentBuilder {
Init: component.InitConfigComponent,
IsInitialized: component.ConfigComponentIsInitialized,
OpenHandler: func(r *FSRepo) error {
cc := component.ConfigComponent{}
cc.SetPath(r.path)
if err := cc.Open(); err != nil {
c := component.ConfigComponent{}
c.SetPath(r.path)
if err := c.Open(); err != nil {
return err
}
r.configComponent = cc
r.configComponent = c
return nil
},
},
// TODO add datastore builder
// DatastoreComponent
componentBuilder{
Init: component.InitDatastoreComponent,
IsInitialized: component.DatastoreComponentIsInitialized,
OpenHandler: func(r *FSRepo) error {
c := component.DatastoreComponent{}
c.SetPath(r.path)
if err := c.Open(); err != nil {
return err
}
r.datastoreComponent = c
return nil
},
},
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment