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.ConfigSource
Env.PropertySource for Config .
|
static class |
Env.MapSource
Env.PropertySource for Map .
|
static interface |
Env.PropertySource
Property source for Env.Resolver
|
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> |
get(Class<T> key)
Get an object by key or empty when missing.
|
<T> Optional<T> |
get(com.google.inject.Key<T> key)
Get an object by key or empty when missing.
|
default <T> Optional<T> |
ifMode(String name, Supplier<T> fn)
Runs the callback function if the current env matches the given name.
|
Locale |
locale() |
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() |
default <T> Env |
set(Class<T> key, T value)
Add a global object.
|
<T> Env |
set(com.google.inject.Key<T> key, T value)
Add a global object.
|
List<org.jooby.funzy.Throwing.Consumer<Registry>> |
startedTasks() |
List<org.jooby.funzy.Throwing.Consumer<Registry>> |
startTasks() |
List<org.jooby.funzy.Throwing.Consumer<Registry>> |
stopTasks() |
<T> T |
unset(com.google.inject.Key<T> key)
Remove a global object.
|
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
@Nonnull Router router() throws UnsupportedOperationException
Router
.
UnsupportedOperationException
- if router isn't available.
@Nonnull com.typesafe.config.Config config()
@Nonnull default Env.ServiceKey serviceKey()
@Nonnull 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.
@Nonnull default Env.Resolver resolver()
Env.Resolver
.
@Nonnull default <T> Optional<T> ifMode(String name, Supplier<T> fn)
T
- A resulting type.
name
- A name to test for.
fn
- A callback function.
@Nonnull default Function<String,String> xss(String... xss)
xss
- XSS to combine.
@Nonnull Env xss(String name, Function<String,String> escaper)
name
- Escape's name.
escaper
- Escape function.
@Nonnull List<org.jooby.funzy.Throwing.Consumer<Registry>> startTasks()
@Nonnull List<org.jooby.funzy.Throwing.Consumer<Registry>> startedTasks()
@Nonnull List<org.jooby.funzy.Throwing.Consumer<Registry>> stopTasks()
@Nonnull <T> Env set(com.google.inject.Key<T> key, T value)
T
- Object type.
key
- Object key.
value
- Object value.
@Nonnull default <T> Env set(Class<T> key, T value)
T
- Object type.
key
- Object key.
value
- Object value.
@Nullable <T> T unset(com.google.inject.Key<T> key)
T
- Object type.
key
- Object key.
@Nonnull <T> Optional<T> get(com.google.inject.Key<T> key)
T
- Object type.
key
- Object key.
Copyright © 2019. All rights reserved.