engine: Add setters for the trait interfaces

Turns out it's useful to wholesale set the entire struct.
This commit is contained in:
James Shubin
2018-12-29 01:13:31 -05:00
parent bdc33cd421
commit 4489076fac
6 changed files with 30 additions and 0 deletions

View File

@@ -31,6 +31,10 @@ type EdgeableRes interface {
// trait. // trait.
AutoEdgeMeta() *AutoEdgeMeta AutoEdgeMeta() *AutoEdgeMeta
// SetAutoEdgeMeta lets you set all of the meta params for the automatic
// edges trait in a single call.
SetAutoEdgeMeta(*AutoEdgeMeta)
// UIDs includes all params to make a unique identification of this // UIDs includes all params to make a unique identification of this
// object. // object.
UIDs() []ResUID // most resources only return one UIDs() []ResUID // most resources only return one

View File

@@ -34,6 +34,10 @@ type GroupableRes interface {
// grouping trait. // grouping trait.
AutoGroupMeta() *AutoGroupMeta AutoGroupMeta() *AutoGroupMeta
// SetAutoGroupMeta lets you set all of the meta params for the
// automatic grouping trait in a single call.
SetAutoGroupMeta(*AutoGroupMeta)
// GroupCmp compares two resources and decides if they're suitable for // GroupCmp compares two resources and decides if they're suitable for
//grouping. This usually needs to be unique to your resource. //grouping. This usually needs to be unique to your resource.
GroupCmp(res GroupableRes) error GroupCmp(res GroupableRes) error

View File

@@ -44,6 +44,10 @@ var DefaultMetaParams = &MetaParams{
type MetaRes interface { type MetaRes interface {
// MetaParams lets you get or set meta params for the resource. // MetaParams lets you get or set meta params for the resource.
MetaParams() *MetaParams MetaParams() *MetaParams
// SetMetaParams lets you set all of the meta params for the resource in
// a single call.
SetMetaParams(*MetaParams)
} }
// MetaParams provides some meta parameters that apply to every resource. // MetaParams provides some meta parameters that apply to every resource.

View File

@@ -40,3 +40,9 @@ func (obj *Edgeable) AutoEdgeMeta() *engine.AutoEdgeMeta {
} }
return obj.meta return obj.meta
} }
// SetAutoEdgeMeta lets you set all of the meta params for the automatic edges
// trait in a single call.
func (obj *Edgeable) SetAutoEdgeMeta(meta *engine.AutoEdgeMeta) {
obj.meta = meta
}

View File

@@ -47,6 +47,12 @@ func (obj *Groupable) AutoGroupMeta() *engine.AutoGroupMeta {
return obj.meta return obj.meta
} }
// SetAutoGroupMeta lets you set all of the meta params for the automatic
// grouping trait in a single call.
func (obj *Groupable) SetAutoGroupMeta(meta *engine.AutoGroupMeta) {
obj.meta = meta
}
// GroupCmp compares two resources and decides if they're suitable for grouping. // GroupCmp compares two resources and decides if they're suitable for grouping.
// You'll probably want to override this method when implementing a resource... // You'll probably want to override this method when implementing a resource...
// This base implementation assumes not, so override me! // This base implementation assumes not, so override me!

View File

@@ -38,3 +38,9 @@ func (obj *Meta) MetaParams() *engine.MetaParams {
} }
return obj.meta return obj.meta
} }
// SetMetaParams lets you set all of the meta params for the resource in a
// single call.
func (obj *Meta) SetMetaParams(meta *engine.MetaParams) {
obj.meta = meta
}