Skip to content

Commit 03b073b

Browse files
authored
Expose more functions for datamodel access (#36)
1 parent a33ba77 commit 03b073b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

datamodel/datamodel.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ func (dm *DataModel) Version() string {
6565
return string(dm.version)
6666
}
6767

68+
// Each iterates over all parameters in the DataModel. Iteration can be stopped
69+
// by returning false from the callback function.
70+
func (dm *DataModel) Each(fn func(p Parameter) (cont bool)) {
71+
dm.values.forEach(func(p Parameter) (cont bool) {
72+
return fn(p)
73+
})
74+
}
75+
6876
// GetAll returns one or more parameters prefixed with the given path.
6977
func (dm *DataModel) GetAll(path string) (params []Parameter, ok bool) {
7078
if !strings.HasSuffix(path, ".") {

datamodel/parameter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ func NormalizeParameters(params map[string]Parameter) {
3333
}
3434
}
3535

36+
// Name returns parameter name.
37+
func (p Parameter) Name() string {
38+
tokens := strings.Split(p.Path, ".")
39+
return tokens[len(tokens)-1]
40+
}
41+
3642
// GetValue returns a parameter value. If the parameter has a generator function
3743
// it will be used to produce a value, otherwise the value from the parameter
3844
// will be returned.

0 commit comments

Comments
 (0)