Class

zio.config.ConfigSourceModule.ConfigSource

Reader

Related Doc: package ConfigSource

Permalink

case class Reader(names: Set[ConfigSourceName], access: MemoizableManagedReader) extends ConfigSource with Product with Serializable

Self Type
Reader
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Reader
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. ConfigSource
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Reader(names: Set[ConfigSourceName], access: MemoizableManagedReader)

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def <>(that: ⇒ Reader): ConfigSource

    Permalink

    <> is an alias to orElse.

    <> is an alias to orElse. Try this (configSource), and if it fails, try that (configSource)

    For example:

    Given three configSources, configSource1, configSource2 and configSource3, such that configSource1 and configSource2 will only have id and configSource3 act as a global fall-back source.

    The following config tries to fetch Id from configSource1, and if fails, it tries configSource2, and if both fails it gets from configSource3. Age will be fetched only from configSource3.

    val config = (string("Id") from (configSource1 orElse configSource2) zip int("Age")).to[Person]
    read(config from configSource3)
  4. def <>(that: ConfigSource): ConfigSource

    Permalink
    Definition Classes
    ConfigSource
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. val access: MemoizableManagedReader

    Permalink
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. def at(propertyTreePath: PropertyTreePath[K]): ConfigSource

    Permalink
    Definition Classes
    ConfigSource
  9. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. def mapKeys(f: (K) ⇒ K): ConfigSource

    Permalink

    Transform keys before getting queried from source.

    Transform keys before getting queried from source. Note that, this method could be hardly useful. Most of the time all you need to use is mapKeys in ConfigDescriptor i.e, read(descriptor[Config].mapKeys(f) from ConfigSource.fromMap(source))

    If you are still curious to understand mapKeys in ConfigSource, then read on, or else avoid a confusion.

    case class Hello(a: String, b: String)
    val config: ConfigDescriptor[Hello] = (string("a") zip string("b")).to[Hello]
    
    However your source is different for some reason (i.e, its not `a` and `b`). Example:
    {
      "aws_a" : "1"
      "aws_b" : "2"
    }
    
    If you are not interested in changing the `descriptor` or `case class`, you have a freedom
    to pre-map keys before its queried from ConfigSource
    
    val removeAwsPrefix  = (s: String) = s.replace("aws", "")
    
    val source = ConfigSource.fromMap(map)
    val updatedSource = source.mapKeys(removeAwsPrefix)
    
    read(config from updatedSource)
    
    // This is exactly the same as
    
    def addAwsPrefix(s: String) = "aws_" + s
    read(config.mapKeys(addAwsPrefix) from source)
    Definition Classes
    ConfigSource
  15. def memoize: ConfigSource

    Permalink

    Memoize the effect required to form the Reader.

    Memoize the effect required to form the Reader.

    Every ConfigSource at the core is just a Reader, which is essentially a function that goes from PropertyTreePath to an actual PropertyTree. i.e, f: PropertyTreePath[String] => IO[ReadError[String], PropertyTree[String, String] Later on for each key represented as PropertyTreePath[String] internally, f is used to applied to get the value as a PropertyTree itself.

    Internal details:

    This function f can be retrieved under an ZManaged effect. This implies it may involve an IO with managing resources to even form this function. Example: In order to retrieve a property-tree corresponding to a key (PropertyTreePath), it requires a database connection in the very first instance.

    // pseudo-logic, doesn't compile

    val source: ConfigSource = ConfigSource.Reader( ZManaged(getDatabaseConnection) .flatMap(connection => (key: PropertyTreePath[String] => IO.effect(connection.getStatement.executeQuery(s"get key from table"))) )

    Note that ConfigSource has a generalised memoize function that allows you to memoize the effect required to form the function. In the context of the above example, with source.memoize we acquire only a single connection to retrieve the values for all the keys in your product/coproduct for an instance of read.

    Definition Classes
    ConfigSource
  16. val names: Set[ConfigSourceName]

    Permalink
  17. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  20. def orElse(that: Reader): Reader

    Permalink

    Try this (configSource), and if it fails, try that (configSource)

    Try this (configSource), and if it fails, try that (configSource)

    For example:

    Given three configSources, configSource1, configSource2 and configSource3, such that configSource1 and configSource2 will only have id and configSource3 act as a global fall-back source.

    The following config tries to fetch Id from configSource1, and if fails, it tries configSource2, and if both fails it gets from configSource3. Age will be fetched only from configSource3.

    val config = (string("Id") from (configSource1 orElse configSource2) zip int("Age")).to[Person]
    read(config from configSource3)
  21. def orElse(that: ConfigSource): ConfigSource

    Permalink
    Definition Classes
    ConfigSource
  22. def run: Reader

    Permalink
    Definition Classes
    ConfigSource
  23. def runTree(path: PropertyTreePath[K]): IO[ReadError[K], PropertyTree[K, V]]

    Permalink
    Definition Classes
    ConfigSource
  24. def sourceNames: Set[ConfigSourceName]

    Permalink
    Definition Classes
    ConfigSource
  25. def strictlyOnce: ZIO[Any, ReadError[K], ConfigSource]

    Permalink

    With strictlyOnce, regardless of the number of times read is invoked, the effect required to form the Reader in ConfigSource is evaluated strictly once.

    With strictlyOnce, regardless of the number of times read is invoked, the effect required to form the Reader in ConfigSource is evaluated strictly once. Use strictlyOnce only if it's really required.

    In a normal scenarios, everytime read is invoked (as in read(desc from source)), it should read from the real source.

    val sourceZIO = ConfigSource.fromPropertiesFile(...).strictlyOnce
    
    for {
      src     <- sourceZIO
      result1 <- read(config from src)
      result2 <- read(config from src)
    } yield (result1, result2)

    In this case, the propertiesFile is read only once.

    vs

    val source: ConfigSource =
      ConfigSource.fromPropertiesFile(...).memoize
    
    for {
      result1 <- read(config from source)
      result2 <- read(config from source)
    } yield (result1, result2)

    In this case, the propertiesFile is read once per each read, i.e, twice.

    Definition Classes
    ConfigSource
    Annotations
    @silent( "a type was inferred to be `Any`" )
  26. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  27. def toLayer: ZLayer[Any, ReadError[K], ConfigSource]

    Permalink

    A Layer is assumed to be "memoized" by default, i.e the effect required to form the reader (refer ConfigSource docs) is executed strictly once regardless of number of keys involved, or the number the reads invoked.

    A Layer is assumed to be "memoized" by default, i.e the effect required to form the reader (refer ConfigSource docs) is executed strictly once regardless of number of keys involved, or the number the reads invoked.

    Definition Classes
    ConfigSource
  28. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from ConfigSource

Inherited from AnyRef

Inherited from Any

Ungrouped