generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoption_relevantif.go
49 lines (44 loc) · 1.06 KB
/
option_relevantif.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
package ferrite
import (
"reflect"
"github.com/dogmatiq/ferrite/internal/variable"
)
// RelevantIf is an option that enables a variable set only if the value
// obtained from another set, s, is "truthy" (not the zero-value).
//
// A "irrelevant" variable set behaves as though its environment variables are
// undefined, irrespective of the actual values of the variables and any default
// values.
func RelevantIf(s VariableSet, _ ...RelevantIfOption) interface {
RequiredOption
OptionalOption
DeprecatedOption
} {
return option{
ApplyToSpec: func(b variable.SpecBuilder) {
for _, v := range s.variables() {
variable.EstablishRelationships(
variable.RefersTo{
Subject: b.Peek(),
RefersTo: v.Spec(),
},
variable.DependsOn{
Subject: b.Peek(),
DependsOn: v.Spec(),
},
)
b.Precondition(
func() bool {
return !reflect.ValueOf(
s.value(),
).IsZero()
},
)
}
},
}
}
// RelevantIfOption changes the behavior of the RelevantIf() option.
type RelevantIfOption interface {
future()
}