Skip to content

Commit

Permalink
Expose errorRule and endpoint rule functions for override in RuleEval…
Browse files Browse the repository at this point in the history
…uator
  • Loading branch information
rcoh committed Mar 15, 2023
1 parent c0053ec commit aaa523c
Showing 1 changed file with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public Value visitLibraryFunction(FunctionDefinition definition, List<Expression
}

private Value handleRule(Rule rule) {
RuleEvaluator self = this;
return scope.inScope(() -> {
for (Condition condition : rule.getConditions()) {
Value value = evaluateCondition(condition);
Expand All @@ -143,33 +142,42 @@ public Value visitTreeRule(List<Rule> rules) {

@Override
public Value visitErrorRule(Expression error) {
return error.accept(self);
return RuleEvaluator.this.visitErrorRule(error);
}

@Override
public Value visitEndpointRule(Endpoint endpoint) {
Value.Endpoint.Builder builder = Value.Endpoint.builder()
.sourceLocation(endpoint)
.url(endpoint.getUrl()
.accept(RuleEvaluator.this)
.expectString());
endpoint.getProperties()
.forEach((key, value) -> builder.addProperty(key.toString(),
value.accept(RuleEvaluator.this)));
endpoint.getHeaders()
.forEach((name, expressions) -> expressions.forEach(expr -> builder.addHeader(name,
expr.accept(RuleEvaluator.this).expectString())));
return builder.build();
return RuleEvaluator.this.visitEndpointRule(endpoint);
}
});
});
}

public Value visitErrorRule(Expression error) {
return error.accept(this);
}

public Value visitEndpointRule(Endpoint endpoint) {
Value.Endpoint.Builder builder = Value.Endpoint.builder()
.sourceLocation(endpoint)
.url(endpoint.getUrl()
.accept(RuleEvaluator.this)
.expectString());
endpoint.getProperties()
.forEach((key, value) -> builder.addProperty(key.toString(),
value.accept(RuleEvaluator.this)));
endpoint.getHeaders()
.forEach((name, expressions) -> expressions.forEach(expr -> builder.addHeader(name,
expr.accept(RuleEvaluator.this).expectString())));
return builder.build();

}

public Value evaluateCondition(Condition condition) {
Value value = condition.getFn().accept(this);
if (!value.isNone()) {
condition.getResult().ifPresent(res -> scope.insert(res, value));
}
return value;
}
}
}

0 comments on commit aaa523c

Please sign in to comment.