Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger-style provider definition #5

Open
FilipMalczak opened this issue Jan 6, 2022 · 0 comments
Open

Logger-style provider definition #5

FilipMalczak opened this issue Jan 6, 2022 · 0 comments

Comments

@FilipMalczak
Copy link

I feel that contracts serve quite a similar role as loggers - they are bug tracking tools at their core (lets not get into log parsing right now, ok?). In the spirit of logger configs (e.g. 1, 2) how about we let user configure policies package-/class-wide?

I'd imagine that,

given a config file like:

providers:
  all-policies:
    require: check
    ensure: check
    neverGetHere: check

configure: #very debatable
  _: all-policies # means "by default";also debatable
  org.example:
    require: pass
  org.depdendency:
    require: pass
    ensure: pass
  org.example.newfeature.AType:
    neverGetHere: pass #stupid idea for examples sake

we'd need a policy like:

class ConfigurableProvider implements AssertiveProvider {
  final static CheckPolicy check = new CheckingPolicy();
  final static CheckPolicy pass = new NonCheckingPolicy();
  final static UnreachablePolicy ignore = new DoNothingPolicy();
  final static UnreachablePolicy goNuts = new NeverGetHerePolicy();

  Config config;

  CheckPolicy requirePolicy(){
    if (config.for(getCallerClass() == ConfigValue.CHECK) {
      return check;
    } else {
      return pass;
    }
  }

  (...) //you can guess for ensure
  
  UnreachablePolicy neverGetHerePolicy(){
    if (config.for(getCallerClass() == ConfigValue.CHECK) {
      return goNuts;
    } else {
      return ignore;
    }
  }
}

This was written ad-hoc, so it terribly simplified. I'd be happy to start working on PR, but first I wanted to discuss if that's the direction you wanna go with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant