@@ -14,7 +14,11 @@ component singleton accessors="true" {
14
14
" applicationHostname" : " ApplicationHostnameStrategy@unleashsdk"
15
15
};
16
16
17
- public boolean function isEnabled ( required string name , boolean defaultValue = false ) {
17
+ public boolean function isEnabled (
18
+ required string name ,
19
+ struct additionalContext = {},
20
+ boolean defaultValue = false
21
+ ) {
18
22
var feature = getFeature ( arguments .name );
19
23
if ( isNull ( feature ) ) {
20
24
return arguments .defaultValue ;
@@ -24,27 +28,37 @@ component singleton accessors="true" {
24
28
return false ;
25
29
}
26
30
31
+ var context = getContext ( arguments .additionalContext );
32
+
33
+ if ( feature .strategies .isEmpty () ) {
34
+ return true ;
35
+ }
36
+
27
37
for ( var strategyData in feature .strategies ) {
28
38
var strategy = getStrategy ( strategyData .name );
29
39
if ( isNull ( strategy ) ) {
30
40
return false ;
31
41
}
32
42
33
43
param strategyData .constraints = [];
34
- if ( ! satisfiesConstraints ( strategyData .constraints ) ) {
44
+ if ( ! satisfiesConstraints ( strategyData .constraints , context ) ) {
35
45
continue ;
36
46
}
37
47
38
48
param strategyData .parameters = {};
39
- if ( ! strategy .isEnabled ( strategyData .parameters , getContext () ) ) {
40
- return false ;
49
+ if ( strategy .isEnabled ( strategyData .parameters , context ) ) {
50
+ return true ;
41
51
}
42
52
}
43
53
44
- return true ;
54
+ return false ;
45
55
}
46
56
47
- public boolean function isDisabled ( required string name , boolean defaultValue = false ) {
57
+ public boolean function isDisabled (
58
+ required string name ,
59
+ struct additionalContext = {},
60
+ boolean defaultValue = false
61
+ ) {
48
62
return ! isEnabled ( argumentCollection = arguments );
49
63
}
50
64
@@ -130,25 +144,25 @@ component singleton accessors="true" {
130
144
return variables .client .get ( " /client/features" ).json ().features ;
131
145
}
132
146
133
- private boolean function satisfiesConstraints ( required array constraints ) {
147
+ private boolean function satisfiesConstraints ( required array constraints , required struct context ) {
134
148
for ( var constraint in arguments .constraints ) {
135
- if ( ! satisfiesConstraint ( constraint ) ) {
149
+ if ( ! satisfiesConstraint ( constraint , arguments . context ) ) {
136
150
return false ;
137
151
}
138
152
}
139
153
return true ;
140
154
}
141
155
142
- private boolean function satisfiesConstraint ( required struct constraint ) {
143
- var context = getContext ();
156
+ private boolean function satisfiesConstraint ( required struct constraint , required struct context ) {
144
157
var contextValue = context [ arguments .constraint .contextName ];
145
158
var valuePresent = arrayContainsNoCase ( arguments .constraint .values , contextValue );
146
159
return arguments .constraint .operator == " IN" ? valuePresent : ! valuePresent ;
147
160
}
148
161
149
- private struct function getContext () {
162
+ private struct function getContext ( struct additionalContext = {} ) {
150
163
param request .unleashContext = generateContext ();
151
- return request .unleashContext ;
164
+ structAppend ( arguments .additionalContext , request .unleashContext , false );
165
+ return arguments .additionalContext ;
152
166
}
153
167
154
168
private struct function generateContext () {
0 commit comments