Packages

  • package root
    Definition Classes
    root
  • package net
    Definition Classes
    root
  • package cakesolutions
    Definition Classes
    net
  • package config

    Using Typesafe config we read in and parse configuration files.

    Using Typesafe config we read in and parse configuration files. Paths into these files are then retrieved and type checked using Ficus.

    Using a lightweight DSL, we are able to then check and validate these type checked values. For example, given that the Typesafe configuration:

    top-level-name = "test"
    test {
      nestedVal = 50.68
      nestedDuration = 4 h
      nestedList = []
      context {
        valueInt = 30
        valueStr = "test string"
        valueDuration = 12 ms
        valueStrList = [ "addr1:10", "addr2:20", "addr3:30" ]
        valueDoubleList = [ 10.2, 20, 0.123 ]
      }
    }

    has been parsed and read into an implicit of type Config, then we are able to validate that the value at the path test.nestedVal has type Double and that it satisfies specified size bounds as follows:

    case object ShouldBeAPercentageValue extends Exception
    
    validate[Double]("test.nestedVal", ShouldBeAPercentageValue)(n => 0 <= n && n <= 100)

    If the configuration value at path test.nestedVal fails to pass the percentage bounds check, then Left(ShouldBeAPercentageValue) is returned.

    Likewise, we can enforce that all values in the array at the path test.context.valueStrList match the regular expression pattern [a-z0-9]+:[0-9]+ as follows:

    case object ShouldBeASocketValue extends Exception
    
    validate[List[String]]("test.context.valueStrList", ShouldBeASocketValue)(_.matches("[a-z0-9]+:[0-9]+"))

    In some instances, we may not care about checking the value at a configuration path. In these cases we can use unchecked:

    unchecked[FiniteDuration]("test.nestedDuration")
    Definition Classes
    cakesolutions
  • ConfigError
  • FileNotFound
  • MissingValue
  • NullValue
  • PathSpec
  • RequiredValueNotSet
  • ValueError
  • ValueErrors
  • ValueFailure
  • optional
  • required

package config

Using Typesafe config we read in and parse configuration files. Paths into these files are then retrieved and type checked using Ficus.

Using a lightweight DSL, we are able to then check and validate these type checked values. For example, given that the Typesafe configuration:

top-level-name = "test"
test {
  nestedVal = 50.68
  nestedDuration = 4 h
  nestedList = []
  context {
    valueInt = 30
    valueStr = "test string"
    valueDuration = 12 ms
    valueStrList = [ "addr1:10", "addr2:20", "addr3:30" ]
    valueDoubleList = [ 10.2, 20, 0.123 ]
  }
}

has been parsed and read into an implicit of type Config, then we are able to validate that the value at the path test.nestedVal has type Double and that it satisfies specified size bounds as follows:

case object ShouldBeAPercentageValue extends Exception

validate[Double]("test.nestedVal", ShouldBeAPercentageValue)(n => 0 <= n && n <= 100)

If the configuration value at path test.nestedVal fails to pass the percentage bounds check, then Left(ShouldBeAPercentageValue) is returned.

Likewise, we can enforce that all values in the array at the path test.context.valueStrList match the regular expression pattern [a-z0-9]+:[0-9]+ as follows:

case object ShouldBeASocketValue extends Exception

validate[List[String]]("test.context.valueStrList", ShouldBeASocketValue)(_.matches("[a-z0-9]+:[0-9]+"))

In some instances, we may not care about checking the value at a configuration path. In these cases we can use unchecked:

unchecked[FiniteDuration]("test.nestedDuration")
Linear Supertypes
FicusInstances, URLReader, URIReaders, LocalDateReader, PeriodReader, ISOZonedDateTimeReader, BigNumberReaders, ConfigValueReader, TryReader, DurationReaders, ConfigReader, CollectionReaders, OptionReader, SymbolReader, StringReader, AnyValReaders, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. config
  2. FicusInstances
  3. URLReader
  4. URIReaders
  5. LocalDateReader
  6. PeriodReader
  7. ISOZonedDateTimeReader
  8. BigNumberReaders
  9. ConfigValueReader
  10. TryReader
  11. DurationReaders
  12. ConfigReader
  13. CollectionReaders
  14. OptionReader
  15. SymbolReader
  16. StringReader
  17. AnyValReaders
  18. AnyRef
  19. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. sealed trait ConfigError extends AnyRef

    General reasons for why a config value might fail to be validated by validate.

  2. final case class FileNotFound(file: String, reason: Throwable) extends ConfigError with Product with Serializable
  3. sealed trait PathSpec extends AnyRef

    Ensures that the specified path has a value defined for it.

    Ensures that the specified path has a value defined for it. This may be achieved:

    • at the Typesafe configuration file level: the path must exist and have a non-null value
    • using a sentinal value: the path has the sentinal value if and only if it has not been set or assigned to.
  4. type ValidationFailure[Value] = Validated[NonEmptyList[ValueFailure], Value]

    Applicative functor for value validation

  5. sealed trait ValueError extends AnyRef

    Reasons why we might fail to parse a value from the config file

  6. final case class ValueErrors(errors: ValueError*) extends ConfigError with Product with Serializable
  7. final case class ValueFailure(path: String, reason: Throwable) extends ValueError with Product with Serializable
  8. final case class optional(value: String) extends PathSpec with Product with Serializable
  9. final case class required extends PathSpec with Product with Serializable

Value Members

  1. implicit val bigDecimalReader: ValueReader[BigDecimal]
    Definition Classes
    BigNumberReaders
  2. implicit val bigIntReader: ValueReader[BigInt]
    Definition Classes
    BigNumberReaders
  3. implicit val booleanValueReader: ValueReader[Boolean]
    Definition Classes
    AnyValReaders
  4. implicit val configValueReader: ValueReader[Config]
    Definition Classes
    ConfigReader
  5. implicit val configValueValueReader: ValueReader[ConfigValue]
    Definition Classes
    ConfigValueReader
  6. implicit val doubleValueReader: ValueReader[Double]
    Definition Classes
    AnyValReaders
  7. implicit def durationReader: ValueReader[Duration]
    Definition Classes
    DurationReaders
  8. implicit val ficusConfigValueReader: ValueReader[FicusConfig]
    Definition Classes
    ConfigReader
  9. implicit def finiteDurationReader: ValueReader[FiniteDuration]
    Definition Classes
    DurationReaders
  10. implicit val intValueReader: ValueReader[Int]
    Definition Classes
    AnyValReaders
  11. implicit val isoZonedDateTimeReader: ValueReader[ZonedDateTime]
    Definition Classes
    ISOZonedDateTimeReader
  12. implicit val javaURIReader: ValueReader[URI]
    Definition Classes
    URIReaders
  13. implicit val javaURLReader: ValueReader[URL]
    Definition Classes
    URLReader
  14. implicit val localDateReader: ValueReader[LocalDate]
    Definition Classes
    LocalDateReader
  15. implicit val longValueReader: ValueReader[Long]
    Definition Classes
    AnyValReaders
  16. implicit def mapValueReader[A](implicit entryReader: ValueReader[A]): ValueReader[Map[String, A]]
    Definition Classes
    CollectionReaders
  17. implicit def optionValueReader[A](implicit valueReader: ValueReader[A]): ValueReader[Option[A]]
    Definition Classes
    OptionReader
  18. implicit val periodReader: ValueReader[Period]
    Definition Classes
    PeriodReader
  19. implicit val stringValueReader: ValueReader[String]
    Definition Classes
    StringReader
  20. implicit val symbolValueReader: ValueReader[Symbol]
    Definition Classes
    SymbolReader
  21. implicit def toFicusConfig(config: Config): FicusConfig
  22. implicit def toRefinementType[Base, Refinement](implicit reader: ValueReader[Base], witness: Validate[Base, Refinement]): ValueReader[Refined[Base, Refinement]]
  23. implicit def traversableReader[C[_], A](implicit entryReader: ValueReader[A], cbf: CanBuildFrom[Nothing, A, C[A]]): ValueReader[C[A]]
    Definition Classes
    CollectionReaders
  24. implicit def tryValueReader[A](implicit valueReader: ValueReader[A]): ValueReader[Try[A]]
    Definition Classes
    TryReader
  25. def unchecked[Value](path: String)(implicit config: Config, reader: ValueReader[Value]): Validated[NonEmptyList[ValueFailure], Value]
  26. def unchecked[Value](pathSpec: PathSpec)(implicit config: Config, reader: ValueReader[Value]): Validated[NonEmptyList[ValueFailure], Value]

    Used to read in a value of type Value.

    Used to read in a value of type Value. Other than checking the values type, no other validation is performed.

    Value

    type we expect the parsed and checked config value to have

    pathSpec

    Typesafe config path to the value we are validating

    config

    the currently in scope config object that we use

    reader

    Ficus ValueReader that we use for type checking the parsed config value

    returns

    either a ValueFailure or the parsed and *unchecked* Value instance

  27. def validate[Value](path: String, failureReason: Throwable)(check: (Value) ⇒ Boolean)(implicit config: Config, reader: ValueReader[Value]): Validated[NonEmptyList[ValueFailure], Value]
  28. def validate[Value](pathSpec: PathSpec, failureReason: Throwable)(check: (Value) ⇒ Boolean)(implicit config: Config, reader: ValueReader[Value]): Validated[NonEmptyList[ValueFailure], Value]

    Used to read in a value of type Value and to then check that value using check.

    Used to read in a value of type Value and to then check that value using check. If check returns false, then we fail with failureReason.

    Value

    type we expect the parsed and checked config value to have

    pathSpec

    Typesafe config path to the value we are validating

    failureReason

    if check fails, the Throwable instance we return

    check

    predicate used to check the configuration value

    config

    the currently in scope config object that we use

    reader

    Ficus ValueReader that we use for type checking the parsed config value

    returns

    either a ValueFailure or the parsed and checked Value instance

  29. def validateConfig[ValidConfig](configFile: String)(check: (Config) ⇒ Validated[NonEmptyList[ValueError], ValidConfig]): Validated[ConfigError, ValidConfig]

    Loads Typesafe config file and then builds the validated case class ValidConfig

    Loads Typesafe config file and then builds the validated case class ValidConfig

    ValidConfig

    the case class type that we are to construct

    configFile

    the root Typesafe config file name

    check

    the builder and validator that we will use to construct the ValidConfig instance

    returns

    either a ConfigError throwable instance or the validated case class ValidConfig

  30. def via[ValidConfig](path: String)(inner: (Config) ⇒ Validated[NonEmptyList[ValueFailure], ValidConfig])(implicit config: Config): Validated[NonEmptyList[ValueFailure], ValidConfig]

    The currently in-scope implicit Config instance is restricted to a specified path

    The currently in-scope implicit Config instance is restricted to a specified path

    ValidConfig

    the case class type that we are to construct

    path

    we restrict our Typesafe config path to this path

    inner

    configuration builder that we will apply to the restricted Config object

    config

    the current in-scope Config object that we need to path restrict

    returns

    either a ValueError or the validated case class ValidConfig

  31. object MissingValue extends Exception with Product with Serializable
  32. object NullValue extends Exception with Product with Serializable
  33. object RequiredValueNotSet extends Exception with Product with Serializable
  34. object required extends Serializable

Inherited from FicusInstances

Inherited from URLReader

Inherited from URIReaders

Inherited from LocalDateReader

Inherited from PeriodReader

Inherited from ISOZonedDateTimeReader

Inherited from BigNumberReaders

Inherited from ConfigValueReader

Inherited from TryReader

Inherited from DurationReaders

Inherited from ConfigReader

Inherited from CollectionReaders

Inherited from OptionReader

Inherited from SymbolReader

Inherited from StringReader

Inherited from AnyValReaders

Inherited from AnyRef

Inherited from Any

Ungrouped