Skip to content

Commit 0e5e79b

Browse files
committed
Add in constraints
1 parent 7f96d2f commit 0e5e79b

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

models/UnleashSDK.cfc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ component singleton accessors="true" {
3131
}
3232

3333
param strategyData.constraints = [];
34-
if ( !strategy.satisfiesConstraints( strategyData.constraints, getContext() ) ) {
35-
continue;
34+
if ( !satisfiesConstraints( strategyData.constraints ) ) {
35+
continue;
3636
}
3737

3838
param strategyData.parameters = {};
@@ -123,6 +123,21 @@ component singleton accessors="true" {
123123
return variables.client.get( "/client/features" ).json().features;
124124
}
125125

126+
private boolean function satisfiesConstraints( required array constraints ) {
127+
for ( var constraint in arguments.constraints ) {
128+
var satisfies = strategy.satisfiesConstraint(
129+
contextName = constraint.contextName,
130+
operator = constraint.operator,
131+
values = constraint.values,
132+
context = getContext()
133+
);
134+
if ( !satisfies ) {
135+
return false;
136+
}
137+
}
138+
return true;
139+
}
140+
126141
private struct function getContext() {
127142
param request.unleashContext = generateContext();
128143
return request.unleashContext;

models/strategies/DefaultStrategy.cfc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
component implements="IStrategy" singleton {
22

3-
public boolean function satisfiesConstraints( array constraints, struct context ) {
3+
public boolean function satisfiesConstraint(
4+
required string contextName,
5+
required string operator,
6+
required array values,
7+
required struct context
8+
) {
49
return true; // spike
510
}
611

7-
public boolean function isEnabled( struct parameters, struct context ) {
12+
public boolean function isEnabled(
13+
required struct parameters,
14+
required struct context
15+
) {
816
return true;
917
}
1018

models/strategies/IStrategy.cfc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
interface {
22

3-
public boolean function satisfiesConstraints( array constraints, struct context );
3+
public boolean function satisfiesConstraint(
4+
required string contextName,
5+
required string operator,
6+
required array values,
7+
required struct context
8+
);
49

5-
public boolean function isEnabled( struct parameters, struct context );
10+
public boolean function isEnabled(
11+
required struct parameters,
12+
required struct context
13+
);
614

715
}

models/strategies/UserWithIdStrategy.cfc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
component implements="IStrategy" singleton {
22

3-
public boolean function satisfiesConstraints( array constraints, struct context ) {
3+
public boolean function satisfiesConstraint(
4+
required string contextName,
5+
required string operator,
6+
required array values,
7+
required struct context
8+
) {
49
return true; // spike
510
}
611

7-
public boolean function isEnabled( struct parameters, struct context ) {
12+
public boolean function isEnabled(
13+
required struct parameters,
14+
required struct context
15+
) {
816
if ( !arguments.parameters.keyExists( "userIds" ) ) {
917
return true;
1018
}

0 commit comments

Comments
 (0)