public interface Env
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.
|
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,
ExSupplier<T> fn)
Runs the callback function if the current env matches the given name.
|
String |
name() |
default String |
resolve(String text)
Returns a string with all substitutions (the
${foo.bar} syntax,
see the
spec) resolved. |
default String |
resolve(String text,
com.typesafe.config.Config source)
Returns a string with all substitutions (the
${foo.bar} syntax,
see the
spec) resolved. |
default String |
resolve(String text,
com.typesafe.config.Config source,
String startDelimiter,
String endDelimiter)
Returns a string with all substitutions (the
${foo.bar} syntax,
see the
spec) resolved. |
default String |
resolve(String text,
String startDelimiter,
String endDelimiter)
Returns a string with all substitutions (the
${foo.bar} syntax,
see the
spec) resolved. |
default <T> Switch<String,T> |
when(Predicate<String> predicate,
T result)
|
default <T> Switch<String,T> |
when(String name,
ExSupplier<T> fn)
|
default <T> Switch<String,T> |
when(String name,
T result)
|
static final Env.Builder DEFAULT
com.typesafe.config.Config config()
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 String resolve(String text, String startDelimiter, String endDelimiter)
${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.startDelimiter
- Start delimiter.endDelimiter
- End delimiter.@Nonnull default String resolve(@Nonnull String text, @Nonnull com.typesafe.config.Config source)
${foo.bar}
syntax,
see the
spec) resolved. Substitutions are looked up using the source
param as the
root object, that is, a substitution ${foo.bar}
will be replaced with
the result of getValue("foo.bar")
.text
- Text to process.source
- The source config to use.@Nonnull default String resolve(@Nonnull String text, @Nonnull com.typesafe.config.Config source, @Nonnull String startDelimiter, @Nonnull String endDelimiter)
${foo.bar}
syntax,
see the
spec) resolved. Substitutions are looked up using the source
param as the
root object, that is, a substitution ${foo.bar}
will be replaced with
the result of getValue("foo.bar")
.text
- Text to process.source
- The source config to usestartDelimiter
- Start delimiter.endDelimiter
- End delimiter.default <T> Optional<T> ifMode(@Nonnull String name, @Nonnull ExSupplier<T> fn) throws Exception
T
- A resulting type.name
- A name to test for.fn
- A callback function.Exception
- If something fails.@Nonnull default <T> Switch<String,T> when(@Nonnull String name, @Nonnull ExSupplier<T> fn)
Switch
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.@Nonnull default <T> Switch<String,T> when(@Nonnull String name, @Nonnull T result)
Switch
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.@Nonnull default <T> Switch<String,T> when(@Nonnull Predicate<String> predicate, @Nonnull T result)
Switch
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.Copyright © 2015. All rights reserved.