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

Make format/s non private #49

Merged
merged 4 commits into from
Jul 20, 2016

Conversation

mdedetrich
Copy link
Contributor

@mdedetrich mdedetrich commented Jul 20, 2016

This makes the various format methods non private. The reasoning is that, if you are unable to make your enums extend PlayEnum or its variants, the only way to create a mapping using an enum is to make a reference to it with the enum method, i.e.

val myEnumMapping = enumeratum.Forms.enum(MyEnum)

Unfortunately the only way you can use this mapping is by reference to a variable, not its type

Form(
    mapping(
        "field" -> myEnumMapping
    )
)

This is because play doesn't have any way to bring an implicit Mapping into scope, only an implicit Formatter. Making the format non privates means that you can do this

object Formats {
    implicit val myEnumFormat = enumeratum.Forms.format(MyEnum)
}

And then you can use plays of to summon an implicit Format from scope

import Formats._
Form(
    mapping(
        "field" -> of[MyEnum]
    )
)

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.672% when pulling 66ce149 on mdedetrich:makeFormatNonPrivate into 972bc40 on lloydmeta:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.672% when pulling 66ce149 on mdedetrich:makeFormatNonPrivate into 972bc40 on lloydmeta:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.672% when pulling 66ce149 on mdedetrich:makeFormatNonPrivate into 972bc40 on lloydmeta:master.

@@ -354,6 +354,34 @@ object GreetingForm {
}
```

Another alternative (if for example your `Enum` cant extend `PlayEnum` or `PlayFormFieldEnum`) is to create an implicit `Format`
Copy link
Owner

Choose a reason for hiding this comment

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

Small typo: cant → can't

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@lloydmeta
Copy link
Owner

Thanks this sounds reasonable, just have a small typo in there that needs fixing and we're good to go 👍

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.672% when pulling 96317d8 on mdedetrich:makeFormatNonPrivate into 972bc40 on lloydmeta:master.

@lloydmeta lloydmeta merged commit 32f83d3 into lloydmeta:master Jul 20, 2016
@lloydmeta
Copy link
Owner

Thanks. 1.4.8 should in the next hour or so be in Maven Central.

@mdedetrich mdedetrich deleted the makeFormatNonPrivate branch July 20, 2016 15:38
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.

3 participants