enumeratum

PlayEnum

trait PlayEnum[A <: EnumEntry] extends Enum[A] with PlayJsonEnum[A] with PlayPathBindableEnum[A] with PlayQueryBindableEnum[A] with PlayFormFieldEnum[A]

An Enum that has a lot of the Play-related implicits built-in so you can avoid boilerplate.

Note, the binders created here are case-sensitive.

Things included are:

Example:

scala> import enumeratum._
scala> import play.api.data.Form
scala> import play.api.libs.json._

scala> sealed trait Greeting extends EnumEntry

scala> object Greeting extends PlayEnum[Greeting] {
     |   val values = findValues
     |   case object Hello   extends Greeting
     |   case object GoodBye extends Greeting
     |   case object Hi      extends Greeting
     |   case object Bye     extends Greeting
     | }

scala> val form = Form("greeting" -> Greeting.formField)
scala> form.bind(Map("greeting" -> "Hello")).value
res0: Option[Greeting] = Some(Hello)

scala> Json.toJson(Greeting.Hello) res1: JsValue = "Hello"

Linear Supertypes
PlayFormFieldEnum[A], PlayQueryBindableEnum[A], PlayPathBindableEnum[A], PlayJsonEnum[A], Enum[A], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. PlayEnum
  2. PlayFormFieldEnum
  3. PlayQueryBindableEnum
  4. PlayPathBindableEnum
  5. PlayJsonEnum
  6. Enum
  7. AnyRef
  8. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def values: IndexedSeq[A]

    Definition Classes
    Enum

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. def findValues: IndexedSeq[A]

    Attributes
    protected
    Definition Classes
    Enum
    Annotations
    @macroImpl( ... )
  12. val formField: Mapping[A]

    Form field for this enum

    Form field for this enum

    Definition Classes
    PlayFormFieldEnum
  13. lazy val fromPath: PathBindableExtractor[A]

    Binder for play.api.routing.sird router

    Binder for play.api.routing.sird router

    Example:

    scala> import play.api.routing.sird._
    scala> import play.api.routing._
    scala> import play.api.mvc._
    scala> import enumeratum._
    
    scala> sealed trait Greeting extends EnumEntry
    
    scala> object Greeting extends PlayEnum[Greeting] {
         |   val values = findValues
         |   case object Hello   extends Greeting
         |   case object GoodBye extends Greeting
         |   case object Hi      extends Greeting
         |   case object Bye     extends Greeting
         | }
    
    scala> val router = Router.from {
         |   case GET(p"/hello/${Greeting.fromPath(greeting)}") => Action {
         |     Results.Ok(s"$greeting")
         |   }
         | }
    scala> router.routes
    res0: Router.Routes = <function1>
    Definition Classes
    PlayPathBindableEnum
  14. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  15. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  16. def indexOf(member: A): Int

    Definition Classes
    Enum
  17. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  18. implicit val jsonFormat: Format[A]

    Definition Classes
    PlayJsonEnum
  19. final lazy val lowerCaseNamesToValuesMap: Map[String, A]

    Definition Classes
    Enum
  20. lazy val namesToValuesMap: Map[String, A]

    Definition Classes
    Enum
  21. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  22. final def notify(): Unit

    Definition Classes
    AnyRef
  23. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  24. implicit val pathBindable: PathBindable[A]

    Implicit path binder for Play's default router

    Implicit path binder for Play's default router

    Definition Classes
    PlayPathBindableEnum
  25. implicit val queryBindable: QueryStringBindable[A]

    Definition Classes
    PlayQueryBindableEnum
  26. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  27. def toString(): String

    Definition Classes
    AnyRef → Any
  28. final lazy val upperCaseNameValuesToMap: Map[String, A]

    Definition Classes
    Enum
  29. final lazy val valuesToIndex: Map[A, Int]

    Definition Classes
    Enum
  30. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. def withName(name: String): A

    Definition Classes
    Enum
    Annotations
    @SuppressWarnings()
  34. def withNameInsensitive(name: String): A

    Definition Classes
    Enum
    Annotations
    @SuppressWarnings()
  35. def withNameInsensitiveOption(name: String): Option[A]

    Definition Classes
    Enum
  36. def withNameLowercaseOnly(name: String): A

    Definition Classes
    Enum
    Annotations
    @SuppressWarnings()
  37. def withNameLowercaseOnlyOption(name: String): Option[A]

    Definition Classes
    Enum
  38. def withNameOption(name: String): Option[A]

    Definition Classes
    Enum
  39. def withNameUppercaseOnly(name: String): A

    Definition Classes
    Enum
    Annotations
    @SuppressWarnings()
  40. def withNameUppercaseOnlyOption(name: String): Option[A]

    Definition Classes
    Enum

Inherited from PlayFormFieldEnum[A]

Inherited from PlayQueryBindableEnum[A]

Inherited from PlayPathBindableEnum[A]

Inherited from PlayJsonEnum[A]

Inherited from Enum[A]

Inherited from AnyRef

Inherited from Any

Ungrouped