Skip to content

Instantly share code, notes, and snippets.

@dtanner
Created April 18, 2016 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtanner/b6d7e3d88578d22fd92aaa390331854f to your computer and use it in GitHub Desktop.
Save dtanner/b6d7e3d88578d22fd92aaa390331854f to your computer and use it in GitHub Desktop.
Example of bad vs good ratpack configuration usage
// a config class with a default value
class LogConfig {
boolean logRequestBody = false
}
// in ratpack, the LogConfig is bound with a prefix of `/logging`
Ratpack.groovy {
bindings {
bindInstance(serverConfig.get('/logging', LogConfig))
}
}
// BAD: code usage of the config just references the `LogConfig` without the prefix
// the end result is that it'll ignore any overrides that use the prefix `/logging`, and only ever use the
// default config value in the LogConfig class.
if (context.serverConfig.get(LogConfig).logRequestBody) {
// do something
}
// i.e. this won't pick up the change
./gradlew -Dlogging.logRequestBody=true run
// GOOD: when accessing the config, make sure the config prefix matches how it's bound in Ratpack.groovy:
if (context.serverConfig.get('/logging', LogConfig).logRequestBody) {
// do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment