sealed abstract class ConfigValue[A] extends AnyRef
Represents a configuration value or a composition of multiple values.
If a configuration value is missing, we can use ConfigValue#or to
try and load the value from elsewhere. ConfigValue#default can be
used to set a default value if all other values are missing. If the
value is optional, ConfigValue#option can be used to default
to None if all values are missing.
Values can be converted to a different type using ConfigValue#as. If the value might contain sensitive details, ConfigValue#secret can be used to redact sensitive details from error messages while also wrapping the value in Secret, preventing the value from being shown.
Sometimes, we first need to load a configuration value to determine
how to continue loading the remaining values. In such cases, it's
suitable to use ConfigValue#flatMap. When loading values in
sequence using flatMap, errors are not accumulated, and so
only the first error will be available.
Parallel composition lets us achieve error accumulation. Functions
like parMapN and parTupled on tuples of ConfigValues loads
several values while also accumulating errors. It is often helpful
to see all errors when loading configurations, so prefer options
which accumulate errors.
Configuration values can be loaded using ConfigValue#load, which loads the value using a specified effect type. If there are errors and we want to deal with them explicitly, ConfigValue#attempt can be used.
scala> import cats.implicits._ import cats.implicits._ scala> case class Config(maxRetries: Int, apiKey: Option[Secret[String]]) defined class Config scala> val maxRetries = env("MAX_RETRIES").or(prop("max.retries")).as[Int].default(5) maxRetries: ConfigValue[Int] = ciris.ConfigValue$$$$anon$$3@5821f472 scala> val apiKey = env("API_KEY").or(prop("api.key")).secret.option apiKey: ConfigValue[Option[Secret[String]]] = ciris.ConfigValue$$$$anon$$3@186ab4b8 scala> val config = (maxRetries, apiKey).parMapN(Config) config: ciris.ConfigValue[Config] = ciris.ConfigValue$$$$anon$$3@565e528c
- Alphabetic
- By Inheritance
- ConfigValue
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
as[B](implicit decoder: ConfigDecoder[A, B]): ConfigValue[B]
Returns a new ConfigValue which attempts to decode the value to the specified type.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
final
def
attempt[F[_]](implicit F: Async[F], context: ContextShift[F]): F[Either[ConfigError, A]]
Returns an effect of the specified type which attempts to load the configuration value.
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
default(value: ⇒ A): ConfigValue[A]
Returns a new ConfigValue which uses the specified default if the value is missing.
Returns a new ConfigValue which uses the specified default if the value is missing.
If a previous default value has been specified, a later default will override the earlier. If a default value is specified for a composition of values, the default will be used in case all values are either missing or are default values themselves.
Using
.default(a)is equivalent to using.or(default(a)). -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
evalMap[F[_], B](f: (A) ⇒ F[B])(implicit F: Effect[F]): ConfigValue[B]
Returns a new ConfigValue which applies the specified effectful function on the value.
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
flatMap[B](f: (A) ⇒ ConfigValue[B]): ConfigValue[B]
Returns a new ConfigValue which loads the specified configuration using the value.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
load[F[_]](implicit F: Async[F], context: ContextShift[F]): F[A]
Returns an effect of the specified type which loads the configuration value.
-
final
def
map[B](f: (A) ⇒ B): ConfigValue[B]
Returns a new ConfigValue which applies the specified function on the value.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
option: ConfigValue[Option[A]]
Returns a new ConfigValue which uses
Noneas the default if the value is missing.Returns a new ConfigValue which uses
Noneas the default if the value is missing.Using
.optionis equivalent to using.map(_.some).default(None). -
final
def
or(value: ⇒ ConfigValue[A]): ConfigValue[A]
Returns a new ConfigValue which uses the specified configuration if the value is missing.
Returns a new ConfigValue which uses the specified configuration if the value is missing.
If the value is a default value, an attempt is made to use the specified configuration, and if that is also missing, the default value remains. Defaults in the specified configuration will override any previous defaults. Errors from both the value and the specified configuration are accumulated.
-
final
def
parFlatMap[B](f: (A) ⇒ ConfigValue[B]): ConfigValue[B]
Returns a new ConfigValue which loads a configuration with the specified dependency.
Returns a new ConfigValue which loads a configuration with the specified dependency.
We can think of ConfigValue#flatMap as first loading a configuration, then creating a separate configuration based on the result. In contrast, ConfigValue#parFlatMap describes a single configuration with dependencies between values.
-
final
def
redacted: ConfigValue[A]
Returns a new ConfigValue with sensitive details redacted from error messages.
Returns a new ConfigValue with sensitive details redacted from error messages.
Using
.redactedis equivalent to using.secret.map(_.value), except without requiring aShowinstance. -
final
def
secret(implicit show: Show[A]): ConfigValue[Secret[A]]
Returns a new ConfigValue which treats the value like it might contain sensitive details.
Returns a new ConfigValue which treats the value like it might contain sensitive details.
Sensitive details are redacted from error messages. The value is wrapped in Secret, which prevents the value from being shown.
Using
.secretis equivalent to using.redacted.map(Secret(_)). -
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()