-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…f `circe-config`
- Loading branch information
Showing
21 changed files
with
340 additions
and
751 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
distage/distage-extension-config/src/main/scala/izumi/distage/config/AppConfigModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package izumi.distage.config | ||
|
||
import com.typesafe.config.Config | ||
import izumi.distage.config.model.AppConfig | ||
import izumi.distage.model.definition.ModuleDef | ||
|
||
class AppConfigModule(appConfig: AppConfig) extends ModuleDef { | ||
def this(config: Config) = this(AppConfig(config)) | ||
|
||
make[AppConfig].fromValue(appConfig) | ||
} | ||
object AppConfigModule { | ||
def apply(appConfig: AppConfig): AppConfigModule = new AppConfigModule(appConfig) | ||
def apply(config: Config): AppConfigModule = new AppConfigModule(config) | ||
} |
23 changes: 2 additions & 21 deletions
23
distage/distage-extension-config/src/main/scala/izumi/distage/config/ConfigModuleDef.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
...age-extension-config/src/main/scala/izumi/distage/config/codec/CirceConfigInstances.scala
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
...tension-config/src/main/scala/izumi/distage/config/codec/CirceDerivationConfigStyle.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...age-extension-config/src/main/scala/izumi/distage/config/codec/PureconfigAutoDerive.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package izumi.distage.config.codec | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox | ||
|
||
/** Derive `pureconfig.ConfigReader` for A and for its fields recursively with `pureconfig-magnolia` */ | ||
final class PureconfigAutoDerive[A](val value: pureconfig.ConfigReader[A]) extends AnyVal | ||
|
||
object PureconfigAutoDerive { | ||
@inline def apply[A](implicit ev: PureconfigAutoDerive[A]): pureconfig.ConfigReader[A] = ev.value | ||
|
||
implicit def materialize[A]: PureconfigAutoDerive[A] = macro CirceDerivationConfigStyleMacro.materializeImpl[A] | ||
|
||
object CirceDerivationConfigStyleMacro { | ||
def materializeImpl[A: c.WeakTypeTag](c: blackbox.Context): c.Expr[PureconfigAutoDerive[A]] = { | ||
import c.universe._ | ||
c.Expr[PureconfigAutoDerive[A]] { | ||
// Yes, this is legal /_\ !! We add an import so that implicit scope is enhanced | ||
// by new config codecs that aren't in Decoder companion object | ||
q"""{ | ||
import _root_.izumi.distage.config.codec.PureconfigInstances._ | ||
new ${weakTypeOf[PureconfigAutoDerive[A]]}(_root_.pureconfig.module.magnolia.auto.reader.exportReader[${weakTypeOf[A]}]) | ||
}""" | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...tage-extension-config/src/main/scala/izumi/distage/config/codec/PureconfigInstances.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package izumi.distage.config.codec | ||
|
||
import com.typesafe.config.ConfigMemorySize | ||
import pureconfig.ConfigReader.Result | ||
import pureconfig.error.CannotConvert | ||
import pureconfig.generic.ProductHint | ||
import pureconfig.{CamelCase, ConfigCursor, ConfigFieldMapping, Exported, error} | ||
|
||
import scala.reflect.classTag | ||
import scala.util.control.NonFatal | ||
|
||
object PureconfigInstances extends PureconfigInstances | ||
trait PureconfigInstances { | ||
/** Override pureconfig's default `snake-case` fields – force CamelCase product-hint */ | ||
implicit def forceCamelCaseProductHint[T]: ProductHint[T] = productHintAny.asInstanceOf[ProductHint[T]] | ||
private[this] val productHintAny: ProductHint[Any] = ProductHint(fieldMapping = ConfigFieldMapping(CamelCase, CamelCase)) | ||
|
||
// use `Exported` so that if user imports their own instances, user instances will have higher priority | ||
implicit final val memorySizeDecoder: Exported[pureconfig.ConfigReader[ConfigMemorySize]] = Exported((cur: ConfigCursor) => { | ||
try Right(cur.value.atKey("m").getMemorySize("m")) catch { | ||
case NonFatal(ex) => | ||
Result.fail(error.ConvertFailure(CannotConvert(cur.value.toString, classTag[ConfigMemorySize].toString, ex.toString), cur)) | ||
} | ||
}) | ||
} |
4 changes: 2 additions & 2 deletions
4
.../distage/config/ConfigPathExtractor.scala → ...onfig/extractor/ConfigPathExtractor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...sion-config/src/main/scala/izumi/distage/config/extractor/ConfigPathExtractorModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package izumi.distage.config.extractor | ||
|
||
import distage.BootstrapModuleDef | ||
import izumi.distage.model.planning.PlanningHook | ||
|
||
class ConfigPathExtractorModule extends BootstrapModuleDef { | ||
many[PlanningHook] | ||
.add[ConfigPathExtractor] | ||
} |
2 changes: 1 addition & 1 deletion
2
...istage-extension-config/src/test/scala/com/github/pshirshov/configapp/TestConfigApp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.