case class Reader(names: Set[ConfigSourceName], access: MemoizableManagedReader) extends ConfigSource with Product with Serializable
- Self Type
- Reader
- Alphabetic
- By Inheritance
- Reader
- Serializable
- Serializable
- Product
- Equals
- ConfigSource
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new Reader(names: Set[ConfigSourceName], access: MemoizableManagedReader)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
<>(that: ⇒ Reader): ConfigSource
<>is an alias toorElse.<>is an alias toorElse. Trythis(configSource), and if it fails, trythat(configSource)For example:
Given three configSources,
configSource1,configSource2andconfigSource3, such that configSource1 and configSource2 will only haveidandconfigSource3act as a global fall-back source.The following config tries to fetch
Idfrom configSource1, and if fails, it triesconfigSource2, and if both fails it gets fromconfigSource3.Agewill be fetched only fromconfigSource3.val config = (string("Id") from (configSource1 orElse configSource2) zip int("Age")).to[Person] read(config from configSource3)
-
def
<>(that: ConfigSource): ConfigSource
- Definition Classes
- ConfigSource
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val access: MemoizableManagedReader
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
at(propertyTreePath: PropertyTreePath[K]): ConfigSource
- Definition Classes
- ConfigSource
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
mapKeys(f: (K) ⇒ K): ConfigSource
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
mapKeysinConfigDescriptori.e,read(descriptor[Config].mapKeys(f) from ConfigSource.fromMap(source))If you are still curious to understand
mapKeysinConfigSource, 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
-
def
memoize: ConfigSource
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 fromPropertyTreePathto an actualPropertyTree. i.e,f: PropertyTreePath[String] => IO[ReadError[String], PropertyTree[String, String]Later on for eachkeyrepresented asPropertyTreePath[String]internally,fis used to applied to get the value as aPropertyTreeitself.Internal details:
This function
fcan 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
ConfigSourcehas a generalisedmemoizefunction that allows you to memoize the effect required to form the function. In the context of the above example, withsource.memoizewe acquire only a single connection to retrieve the values for all the keys in your product/coproduct for an instance ofread.- Definition Classes
- ConfigSource
- val names: Set[ConfigSourceName]
-
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()
-
def
orElse(that: Reader): Reader
Try
this(configSource), and if it fails, trythat(configSource)Try
this(configSource), and if it fails, trythat(configSource)For example:
Given three configSources,
configSource1,configSource2andconfigSource3, such that configSource1 and configSource2 will only haveidandconfigSource3act as a global fall-back source.The following config tries to fetch
Idfrom configSource1, and if fails, it triesconfigSource2, and if both fails it gets fromconfigSource3.Agewill be fetched only fromconfigSource3.val config = (string("Id") from (configSource1 orElse configSource2) zip int("Age")).to[Person] read(config from configSource3)
-
def
orElse(that: ConfigSource): ConfigSource
- Definition Classes
- ConfigSource
-
def
run: Reader
- Definition Classes
- ConfigSource
-
def
runTree(path: PropertyTreePath[K]): IO[ReadError[K], PropertyTree[K, V]]
- Definition Classes
- ConfigSource
-
def
sourceNames: Set[ConfigSourceName]
- Definition Classes
- ConfigSource
-
def
strictlyOnce: ZIO[Any, ReadError[K], ConfigSource]
With
strictlyOnce, regardless of the number of timesreadis invoked, the effect required to form theReaderinConfigSourceis evaluated strictly once.With
strictlyOnce, regardless of the number of timesreadis invoked, the effect required to form theReaderinConfigSourceis evaluated strictly once. UsestrictlyOnceonly if it's really required.In a normal scenarios, everytime
readis invoked (as inread(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`" )
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toLayer: ZLayer[Any, ReadError[K], ConfigSource]
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
-
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()