Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for classes to @safeConfig. #2

Merged
merged 1 commit into from
Jan 21, 2016
Merged

Conversation

ClaireNeveu
Copy link
Contributor

@balagez This PR extends the @safeConfig macro to work on classes so that it can be used with Play 2.4 (in light of scalamacros/paradise#49).

val liftedTypesafeConfig = tq"com.kinja.config.LiftedTypesafeConfig"

// The root element.
val root = q"""lazy val root = com.kinja.config.BootupErrors(com.kinja.config.LiftedTypesafeConfig($underlying, "root"))"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the root object can now be defined as a member of the containing class/object we need to make this lazy so that it doesn't try to reference uninitialized values.

@balagez
Copy link
Contributor

balagez commented Jan 20, 2016

Running sbt test gives me a lot of compile errors like this one:

[error] ~/safe-config/src/test/scala/com/kinja/config/TestConfigs.scala:10: not found: value getConfig
[error]   private val subConfig = getConfig("sub-config")

@balagez
Copy link
Contributor

balagez commented Jan 20, 2016

I tried to make this work the way you described in the readme, but getting these compile errors:

[error] ~/kinja-service-template/app/dependencies/AppLoader.scala:27: not found: type Context
[error] class Bootstrap(context: Context) extends BuiltInComponentsFromContext(context) {
[error]                 ^
[error] ~/kinja-service-template/app/dependencies/AppLoader.scala:31: not found: value getString
[error]     val secret = getString("application.secret")
[error]                  ^
[error] two errors found

(FYI The code does work without the safeConfig annotation, so the imports are fine.)

Similarly, I experimented with the following code:

import com.typesafe.config.Config
import com.kinja.config.safeConfig

@safeConfig("rawConfig")
class AppConfig(private val rawConfig: Config) {

    val secret = getString("application.secret")
}

And got the same errors:

[error] ~/kinja-service-template/app/dependencies/AppConfig.scala:7: not found: type Config
[error] class AppConfig(private val rawConfig: Config) {
[error]                              ^
[error] ~/kinja-service-template/app/dependencies/AppConfig.scala:9: not found: value getString
[error]     val secret = getString("application.secret")
[error]                  ^
[error] two errors found

@ClaireNeveu
Copy link
Contributor Author

@balagez sbt test works fine for me. Can you post the macro output in your failure?

@ClaireNeveu
Copy link
Contributor Author

Nevermind, there was some weird caching going on that allowed it to succeed. I'm looking into those errors now.

@ClaireNeveu
Copy link
Contributor Author

In retrospect, I didn't correctly handle class arguments and protected members when type-checking. Fix incoming.

@ClaireNeveu ClaireNeveu force-pushed the classSupport branch 5 times, most recently from b858a5a to d5aa6ec Compare January 20, 2016 17:01
@ClaireNeveu
Copy link
Contributor Author

@balagez Please test again.

@balagez
Copy link
Contributor

balagez commented Jan 21, 2016

Works perfectly now.

ClaireNeveu added a commit that referenced this pull request Jan 21, 2016
Add support for classes to @safeConfig.
@ClaireNeveu ClaireNeveu merged commit c180375 into master Jan 21, 2016
@ClaireNeveu ClaireNeveu deleted the classSupport branch January 21, 2016 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants