public interface Env extends LifeCycle
A env is represented by it's name. For example: dev
, prod
, etc... A
dev env is special and a module provider could do some special configuration for
development, like turning off a cache, reloading of resources, etc.
Same is true for not dev environments. For example, a module provider might create a high performance connection pool, caches, etc.
By default env is set to dev
, but you can change it by setting the
application.env
property to anything else.
Modifier and Type | Interface and Description |
---|---|
static interface |
Env.Builder
Build an jooby environment.
|
static class |
Env.Resolver
Template literal implementation, replaces
${expression} from a String using a
Config object. |
static class |
Env.ServiceKey
Utility class for generating
Key for named services. |
Modifier and Type | Field and Description |
---|---|
static Env.Builder |
DEFAULT
Default builder.
|
Modifier and Type | Method and Description |
---|---|
com.typesafe.config.Config |
config() |
default <T> Optional<T> |
ifMode(String name,
Supplier<T> fn)
Runs the callback function if the current env matches the given name.
|
Locale |
locale() |
default javaslang.API.Match<String> |
match()
Produces a
API.Match of the current Env . |
String |
name() |
default String |
resolve(String text)
Returns a string with all substitutions (the
${foo.bar} syntax,
see the
spec) resolved. |
default Env.Resolver |
resolver()
Creates a new environment
Env.Resolver . |
Router |
router()
Application router.
|
default Env.ServiceKey |
serviceKey() |
List<javaslang.control.Try.CheckedConsumer<Registry>> |
startedTasks() |
List<javaslang.control.Try.CheckedConsumer<Registry>> |
startTasks() |
List<javaslang.control.Try.CheckedConsumer<Registry>> |
stopTasks() |
default <T> javaslang.control.Option<T> |
when(Predicate<String> predicate,
T result)
Produces a
API.Match of the current Env . |
default <T> javaslang.control.Option<T> |
when(String name,
Supplier<T> fn)
Produces a
API.Match of the current Env . |
default <T> javaslang.control.Option<T> |
when(String name,
T result)
Produces a
API.Match of the current Env . |
Map<String,Function<String,String>> |
xss() |
default Function<String,String> |
xss(String... xss)
Get or chain the required xss functions.
|
Env |
xss(String name,
Function<String,String> escaper)
Set/override a XSS escape function.
|
static final Env.Builder DEFAULT
String name()
Router router() throws UnsupportedOperationException
Router
.UnsupportedOperationException
- if router isn't available.com.typesafe.config.Config config()
Locale locale()
application.lang
.default Env.ServiceKey serviceKey()
default String resolve(String text)
${foo.bar}
syntax,
see the
spec) resolved. Substitutions are looked up using the config()
as the root object,
that is, a substitution ${foo.bar}
will be replaced with
the result of getValue("foo.bar")
.text
- Text to process.default Env.Resolver resolver()
Env.Resolver
.default <T> Optional<T> ifMode(String name, Supplier<T> fn)
T
- A resulting type.name
- A name to test for.fn
- A callback function.default javaslang.API.Match<String> match()
API.Match
of the current Env
.
String accessKey = env.match() .when("dev", () -> "1234") .when("stage", () -> "4321") .when("prod", () -> "abc") .get();
default <T> javaslang.control.Option<T> when(String name, Supplier<T> fn)
API.Match
of the current Env
.
String accessKey = env.when("dev", () -> "1234") .when("stage", () -> "4321") .when("prod", () -> "abc") .get();
T
- A resulting type.name
- A name to test for.fn
- A callback function.default <T> javaslang.control.Option<T> when(String name, T result)
API.Match
of the current Env
.
String accessKey = env.when("dev", "1234") .when("stage", "4321") .when("prod", "abc") .get();
T
- A resulting type.name
- A name to test for.result
- A constant value to return.default <T> javaslang.control.Option<T> when(Predicate<String> predicate, T result)
API.Match
of the current Env
.
String accessKey = env.when("dev", () -> "1234") .when("stage", () -> "4321") .when("prod", () -> "abc") .get();
T
- A resulting type.predicate
- A predicate to use.result
- A constant value to return.default Function<String,String> xss(String... xss)
xss
- XSS to combine.Env xss(String name, Function<String,String> escaper)
name
- Escape's name.escaper
- Escape function.List<javaslang.control.Try.CheckedConsumer<Registry>> startTasks()
List<javaslang.control.Try.CheckedConsumer<Registry>> startedTasks()
Copyright © 2017. All rights reserved.