Skip to content

Commit

Permalink
Remove type alias from core package.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
ruippeixotog committed Aug 6, 2017
1 parent cad39b9 commit 08fa51e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
47 changes: 22 additions & 25 deletions core/src/main/scala/pureconfig/package.scala
Expand Up @@ -19,9 +19,6 @@ import pureconfig.error._

package object pureconfig {

// an alias for a `Derivation` of a `ConfigReader`
private type DerivedConfigReader[A] = Derivation[ConfigReader[A]]

// retrieves a value from a namespace, returning a failure if:
// - one of the parent keys doesn't exist or isn't an object;
// - `allowNullLeaf` is false and the leaf key doesn't exist.
Expand Down Expand Up @@ -51,7 +48,7 @@ package object pureconfig {

// loads a value from a config in a given namespace. All `loadConfig` methods _must_ use this method to get correct
// namespace handling, both in the values to load and in the error messages.
private[this] def loadValue[A](conf: TypesafeConfig, namespace: String)(implicit reader: DerivedConfigReader[A]): Either[ConfigReaderFailures, A] = {
private[this] def loadValue[A](conf: TypesafeConfig, namespace: String)(implicit reader: Derivation[ConfigReader[A]]): Either[ConfigReaderFailures, A] = {
getValue(conf, namespace, reader.value.isInstanceOf[AllowMissingKey]).right.flatMap { cv =>
if (namespace.isEmpty) reader.value.from(cv)
else improveFailures(reader.value.from(cv), namespace, ConfigValueLocation(conf.root()))
Expand All @@ -65,7 +62,7 @@ package object pureconfig {
* `Config` from the configuration files, else a `Failure` with details on why it
* isn't possible
*/
def loadConfig[Config: DerivedConfigReader]: Either[ConfigReaderFailures, Config] =
def loadConfig[Config](implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] =
loadConfig("")

/**
Expand All @@ -76,7 +73,7 @@ package object pureconfig {
* `Config` from the configuration files, else a `Failure` with details on why it
* isn't possible
*/
def loadConfig[Config: DerivedConfigReader](namespace: String): Either[ConfigReaderFailures, Config] = {
def loadConfig[Config](namespace: String)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] = {
for {
_ <- invalidateCaches().right
rawConfig <- load().right
Expand All @@ -92,7 +89,7 @@ package object pureconfig {
* `Config` from the configuration files, else a `Failure` with details on why it
* isn't possible
*/
def loadConfig[Config: DerivedConfigReader](path: Path): Either[ConfigReaderFailures, Config] =
def loadConfig[Config](path: Path)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] =
loadConfig(path, "")

/**
Expand All @@ -104,7 +101,7 @@ package object pureconfig {
* `Config` from the configuration files, else a `Failure` with details on why it
* isn't possible
*/
def loadConfig[Config: DerivedConfigReader](path: Path, namespace: String): Either[ConfigReaderFailures, Config] = {
def loadConfig[Config](path: Path, namespace: String)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] = {
for {
_ <- invalidateCaches().right
rawConfig <- loadFile(path).right
Expand All @@ -113,11 +110,11 @@ package object pureconfig {
}

/** Load a configuration of type `Config` from the given `Config` */
def loadConfig[Config: DerivedConfigReader](conf: TypesafeConfig): Either[ConfigReaderFailures, Config] =
def loadConfig[Config](conf: TypesafeConfig)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] =
loadValue(conf, "")

/** Load a configuration of type `Config` from the given `Config` */
def loadConfig[Config: DerivedConfigReader](conf: TypesafeConfig, namespace: String): Either[ConfigReaderFailures, Config] =
def loadConfig[Config](conf: TypesafeConfig, namespace: String)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] =
loadValue(conf, namespace)

/**
Expand All @@ -128,7 +125,7 @@ package object pureconfig {
* `Config` from the configuration files, else a `Failure` with details on why it
* isn't possible
*/
def loadConfigWithFallback[Config: DerivedConfigReader](conf: TypesafeConfig): Either[ConfigReaderFailures, Config] =
def loadConfigWithFallback[Config](conf: TypesafeConfig)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] =
loadConfigWithFallback(conf, "")

/**
Expand All @@ -140,7 +137,7 @@ package object pureconfig {
* `Config` from the configuration files, else a `Failure` with details on why it
* isn't possible
*/
def loadConfigWithFallback[Config: DerivedConfigReader](conf: TypesafeConfig, namespace: String): Either[ConfigReaderFailures, Config] = {
def loadConfigWithFallback[Config](conf: TypesafeConfig, namespace: String)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] = {
for {
_ <- invalidateCaches().right
rawConfig <- load().right
Expand All @@ -161,7 +158,7 @@ package object pureconfig {
* @return the configuration
*/
@throws[ConfigReaderException[_]]
def loadConfigOrThrow[Config: DerivedConfigReader: ClassTag]: Config = {
def loadConfigOrThrow[Config: ClassTag](implicit reader: Derivation[ConfigReader[Config]]): Config = {
getResultOrThrow(loadConfig[Config])
}

Expand All @@ -172,7 +169,7 @@ package object pureconfig {
* @return the configuration
*/
@throws[ConfigReaderException[_]]
def loadConfigOrThrow[Config: DerivedConfigReader: ClassTag](namespace: String): Config = {
def loadConfigOrThrow[Config: ClassTag](namespace: String)(implicit reader: Derivation[ConfigReader[Config]]): Config = {
getResultOrThrow(loadConfig[Config](namespace))
}

Expand All @@ -183,7 +180,7 @@ package object pureconfig {
* @return the configuration
*/
@throws[ConfigReaderException[_]]
def loadConfigOrThrow[Config: DerivedConfigReader: ClassTag](path: Path): Config = {
def loadConfigOrThrow[Config: ClassTag](path: Path)(implicit reader: Derivation[ConfigReader[Config]]): Config = {
getResultOrThrow(loadConfig[Config](path))
}

Expand All @@ -195,7 +192,7 @@ package object pureconfig {
* @return the configuration
*/
@throws[ConfigReaderException[_]]
def loadConfigOrThrow[Config: DerivedConfigReader: ClassTag](path: Path, namespace: String): Config = {
def loadConfigOrThrow[Config: ClassTag](path: Path, namespace: String)(implicit reader: Derivation[ConfigReader[Config]]): Config = {
getResultOrThrow(loadConfig[Config](path, namespace))
}

Expand All @@ -206,7 +203,7 @@ package object pureconfig {
* @return the configuration
*/
@throws[ConfigReaderException[_]]
def loadConfigOrThrow[Config: DerivedConfigReader: ClassTag](conf: TypesafeConfig): Config = {
def loadConfigOrThrow[Config: ClassTag](conf: TypesafeConfig)(implicit reader: Derivation[ConfigReader[Config]]): Config = {
getResultOrThrow(loadConfig[Config](conf))
}

Expand All @@ -218,7 +215,7 @@ package object pureconfig {
* @return the configuration
*/
@throws[ConfigReaderException[_]]
def loadConfigOrThrow[Config: DerivedConfigReader: ClassTag](conf: TypesafeConfig, namespace: String): Config = {
def loadConfigOrThrow[Config: ClassTag](conf: TypesafeConfig, namespace: String)(implicit reader: Derivation[ConfigReader[Config]]): Config = {
getResultOrThrow(loadConfig[Config](conf, namespace))
}

Expand All @@ -229,7 +226,7 @@ package object pureconfig {
* @return the configuration
*/
@throws[ConfigReaderException[_]]
def loadConfigWithFallbackOrThrow[Config: DerivedConfigReader: ClassTag](conf: TypesafeConfig): Config = {
def loadConfigWithFallbackOrThrow[Config: ClassTag](conf: TypesafeConfig)(implicit reader: Derivation[ConfigReader[Config]]): Config = {
getResultOrThrow(loadConfigWithFallback[Config](conf))
}

Expand All @@ -241,7 +238,7 @@ package object pureconfig {
* @return the configuration
*/
@throws[ConfigReaderException[_]]
def loadConfigWithFallbackOrThrow[Config: DerivedConfigReader: ClassTag](conf: TypesafeConfig, namespace: String): Config = {
def loadConfigWithFallbackOrThrow[Config: ClassTag](conf: TypesafeConfig, namespace: String)(implicit reader: Derivation[ConfigReader[Config]]): Config = {
getResultOrThrow(loadConfigWithFallback[Config](conf, namespace))
}

Expand All @@ -253,7 +250,7 @@ package object pureconfig {
* @param overrideOutputPath Override the path if it already exists
*/
@throws[IllegalArgumentException]
def saveConfigAsPropertyFile[Config: ConfigWriter](conf: Config, outputPath: Path, overrideOutputPath: Boolean = false): Unit = {
def saveConfigAsPropertyFile[Config](conf: Config, outputPath: Path, overrideOutputPath: Boolean = false)(implicit writer: Derivation[ConfigWriter[Config]]): Unit = {
if (!overrideOutputPath && Files.isRegularFile(outputPath)) {
throw new IllegalArgumentException(s"Cannot save configuration in file '$outputPath' because it already exists")
}
Expand All @@ -270,9 +267,9 @@ package object pureconfig {
* @param conf The configuration to write
* @param outputStream The stream in which the configuration should be written
*/
def saveConfigToStream[Config](conf: Config, outputStream: OutputStream)(implicit writer: ConfigWriter[Config]): Unit = {
def saveConfigToStream[Config](conf: Config, outputStream: OutputStream)(implicit writer: Derivation[ConfigWriter[Config]]): Unit = {
val printOutputStream = new PrintStream(outputStream)
val rawConf = writer.to(conf)
val rawConf = writer.value.to(conf)
printOutputStream.print(rawConf.render())
printOutputStream.close()
}
Expand All @@ -286,7 +283,7 @@ package object pureconfig {
*
* @param files Files ordered in decreasing priority containing part or all of a `Config`. Must not be empty.
*/
def loadConfigFromFiles[Config: DerivedConfigReader](files: Traversable[Path]): Either[ConfigReaderFailures, Config] = {
def loadConfigFromFiles[Config](files: Traversable[Path])(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] = {
if (files.isEmpty) {
ConfigConvert.failWithThrowable[Config](new IllegalArgumentException("The config files to load must not be empty."))(None)
} else {
Expand All @@ -306,7 +303,7 @@ package object pureconfig {
* @return the configuration
*/
@throws[ConfigReaderException[_]]
def loadConfigFromFilesOrThrow[Config: DerivedConfigReader: ClassTag](files: Traversable[Path]): Config = {
def loadConfigFromFilesOrThrow[Config: ClassTag](files: Traversable[Path])(implicit reader: Derivation[ConfigReader[Config]]): Config = {
getResultOrThrow[Config](loadConfigFromFiles[Config](files))
}
}
2 changes: 1 addition & 1 deletion docs/support-new-types.md
Expand Up @@ -22,7 +22,7 @@ of `ConfigReader[T]` for that type. This won't compile because there's no `Confi

```scala
loadConfig[Conf](conf)
// <console>:23: error: could not find implicit value for evidence parameter of type pureconfig.DerivedConfigReader[Conf]
// <console>:23: error: could not find implicit value for parameter reader: pureconfig.Derivation[pureconfig.ConfigReader[Conf]]
// loadConfig[Conf](conf)
// ^
```
Expand Down

0 comments on commit 08fa51e

Please sign in to comment.