-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
111 lines (93 loc) · 2.36 KB
/
options.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package sieve
import "reflect"
type Options interface {
HasScopes() bool
HasNextScopes() bool
HasExportKeys() bool
HasExclusions() bool
Scopes() []string
NextScopes() []string
ExportKeys() []string
CheckByExclusions(v ...reflect.Value) bool
}
type OptionsBuilder interface {
Options
SetScopes(scopes ...string) OptionsBuilder
SetExportKeys(keys ...string) OptionsBuilder
SetNextScopes(scopes ...string) OptionsBuilder
PutExclusionStrategy(s ExclusionStrategy) OptionsBuilder
SetIsAnyExclusion(v bool) OptionsBuilder
}
type options struct {
scopes []string // s
nextScopes []string // ns
exportKeys []string // k
exclusions []ExclusionStrategy // e+ (ef, ev)
isAnyExclusion bool // e.any
}
func (o options) HasScopes() bool {
return o.scopes != nil && len(o.scopes) > 0
}
func (o options) HasNextScopes() bool {
return o.nextScopes != nil && len(o.nextScopes) > 0
}
func (o options) HasExportKeys() bool {
return o.exportKeys != nil && len(o.exportKeys) > 0
}
func (o options) HasExclusions() bool {
return o.exclusions != nil && len(o.exclusions) > 0
}
func (o options) Scopes() []string {
return o.scopes
}
func (o options) NextScopes() []string {
return o.nextScopes
}
func (o options) ExportKeys() []string {
return o.exportKeys
}
func (o options) CheckByExclusions(v ...reflect.Value) bool {
if o.exclusions != nil {
for _, exclusion := range o.exclusions {
if exclusion.Check(v...) {
if o.isAnyExclusion {
return true
}
continue
} else if !o.isAnyExclusion {
return false
}
}
return !o.isAnyExclusion
}
return false
}
func (o *options) SetScopes(scopes ...string) OptionsBuilder {
o.scopes = scopes
return o
}
func (o *options) SetNextScopes(scopes ...string) OptionsBuilder {
o.nextScopes = scopes
return o
}
func (o *options) SetExportKeys(keys ...string) OptionsBuilder {
o.exportKeys = keys
return o
}
func (o *options) PutExclusionStrategy(s ExclusionStrategy) OptionsBuilder {
if o.exclusions == nil {
o.exclusions = make([]ExclusionStrategy, 0, 0)
}
o.exclusions = append(o.exclusions, s)
return o
}
func (o *options) SetIsAnyExclusion(v bool) OptionsBuilder {
o.isAnyExclusion = v
return o
}
func BuildOptions(scopes []string, exportKeys []string) OptionsBuilder {
return &options{
scopes: scopes,
exportKeys: exportKeys,
}
}