generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoption.go
72 lines (57 loc) · 2.22 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package ferrite
import "github.com/dogmatiq/ferrite/internal/variable"
// option is an implementation of various option interfaces.
//
// Functions that return options should return an anonymous interface type that
// embeds one or more of the option interfaces.
type option struct {
ApplyToInitConfig func(*initConfig)
ApplyToRegistry func(*variable.Registry)
ApplyToSetConfig func(*variableSetConfig)
ApplyToSpec func(variable.SpecBuilder)
ApplyToRequiredSetConfig func(*variableSetConfig)
ApplyToSpecInRequiredSet func(variable.SpecBuilder)
ApplyToOptionalSetConfig func(*variableSetConfig)
ApplyToSpecInOptionalSet func(variable.SpecBuilder)
ApplyToDeprecatedSetConfig func(*variableSetConfig)
ApplyToSpecInDeprecatedSet func(variable.SpecBuilder)
ApplyToRefersToRelationship func(*variable.RefersTo)
ApplyToSupersedesRelationship func(*variable.Supersedes)
}
func (o option) applyInitOption(cfg *initConfig) {
applyOption(cfg, o.ApplyToInitConfig)
}
func (o option) applyRegistryOption(reg *variable.Registry) {
applyOption(reg, o.ApplyToRegistry)
}
func (o option) applyRequiredOptionToConfig(cfg *variableSetConfig) {
applyOption(cfg, o.ApplyToSetConfig, o.ApplyToRequiredSetConfig)
}
func (o option) applyRequiredOptionToSpec(b variable.SpecBuilder) {
applyOption(b, o.ApplyToSpec, o.ApplyToSpecInRequiredSet)
}
func (o option) applyOptionalOptionToConfig(cfg *variableSetConfig) {
applyOption(cfg, o.ApplyToSetConfig, o.ApplyToOptionalSetConfig)
}
func (o option) applyOptionalOptionToSpec(b variable.SpecBuilder) {
applyOption(b, o.ApplyToSpec, o.ApplyToSpecInOptionalSet)
}
func (o option) applyDeprecatedOptionToConfig(cfg *variableSetConfig) {
applyOption(cfg, o.ApplyToSetConfig, o.ApplyToDeprecatedSetConfig)
}
func (o option) applyDeprecatedOptionToSpec(b variable.SpecBuilder) {
applyOption(b, o.ApplyToSpec, o.ApplyToSpecInDeprecatedSet)
}
func (o option) applyRefersToOption(r *variable.RefersTo) {
applyOption(r, o.ApplyToRefersToRelationship)
}
func (o option) applySupersedesOption(r *variable.Supersedes) {
applyOption(r, o.ApplyToSupersedesRelationship)
}
func applyOption[T any](cfg T, funcs ...func(T)) {
for _, fn := range funcs {
if fn != nil {
fn(cfg)
}
}
}