-
Notifications
You must be signed in to change notification settings - Fork 15
Description
I think the entry point for AccessEvaluator entry point has room for improvement. Currently, the entry point is a static method named of that is overloaded. However, it almost exclusively takes an Authorizations object of some form.
Rather than construct an Authorizations object, then construct a separate AccessEvaluator object, it would probably make more sense to have a method that dangles off of Authorizations that evaluates.
For example:
var evaluator = AccessEvaluator.of(Authorizations.of("a", "b"));
// vs.
var evaluator = Authorizations.of("a", "b").evaluator();What I'm suggesting is similar to the way Java regex Patterns can construct a Matcher. You wouldn't do Matcher m = new Matcher(Pattern.compile("p"), "other");. Instead, you do Pattern.compile("p").matcher("other"). You start with the thing you have, then you derive the related objects from it. In our case, our starting point is the Authorizations.
Also, while Authorizations and AccessExpression also use of as named entry points, I think it makes more sense to use for those than it does for AccessEvaluator. For the first two, you're literally composing them "of" the string provided, because they are simple objects that wrap and represent the thing it is being composed "of". That's not quite true for AccessEvaluator, which isn't merely wrapping, but is a tool to do evaluating work using the Authorizations used to initialize it. I think something like .compile(auths), .using(auths), or even .with(auths) might make more sense. However I'd still rather see if we can do away with it entirely, and just have an entry point off of Authorizations instead.