Trait/Object

ltbs.uniform

UniformMessages

Related Docs: object UniformMessages | package uniform

Permalink

trait UniformMessages[A] extends AnyRef

A content bundle

Typically used for internationalisation but also for customisation of content on given steps of a user-journey.

This is modelled largely around the Messages object in the play framework - albeit with some extra capabilities (such as decomposition), but as such although it can take arguments (Any*)it is not typesafe and has no way of knowing ahead-of-time if content is missing.

Unlike play Messages however, UniformMessages are typed, can be mapped to different types and are also Monoids allowing them to be combined.

val m = UniformMessages.fromMap(
  Map("page1.field2.dateOfBirth" -> List("When were you born?"),
      "dateOfBirth" -> List("Date of birth"))
)

scala> m.get("page1.field2.dateOfBirth")
res1: Option[String] = Some(When were you born?)

scala> m.decomposeOpt("dateOfBirth")
res2: Option[String] = Some(Date of birth)

scala> import cats.implicits._
scala> {m |+| UniformMessages.bestGuess}.apply("page1.step2.EnterYourBillingAddress")
res3: String = Enter Your Billing Address

scala> case class PoorMansHtml(value: String)
defined class PoorMansHtml
scala> m.map(PoorMansHtml)
res4: ltbs.uniform.UniformMessages[PoorMansHtml] = ...
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. UniformMessages
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def get(key: String, args: Any*): Option[A]

    Permalink

    Retrieve a single message for the key, replacing any arguments with the values supplied.

    Retrieve a single message for the key, replacing any arguments with the values supplied. Returns None if the message is not found.

    key

    the lookup identifier for the message

    args

    any arguments to be supplied, how they are handled depends upon the UniformMessages1 implementation, but generally they are injected into the response.

  2. abstract def list(key: String, args: Any*): List[A]

    Permalink

    Retrieve a list of values against a single key, if the key is not found in the messages this will return Nil

Concrete Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. def apply(keys: List[String], args: Any*): A

    Permalink

    Retrieve a single message against the keys, replacing any arguments with the values supplied.

    Retrieve a single message against the keys, replacing any arguments with the values supplied. Throws an exception if no message is found against any of the keys. If there are multiple matches the first one will be used.

    keys

    lookup identifiers for the message, each is tried in turn

    args

    any arguments to be supplied, how they are handled depends upon the UniformMessages1 implementation, but generally they are injected into the response.

  5. def apply(key: String, args: Any*): A

    Permalink

    Retrieve a single message for the key, replacing any arguments with the values supplied.

    Retrieve a single message for the key, replacing any arguments with the values supplied. Throws an exception if the message is not found.

    key

    the lookup identifier for the message

    args

    any arguments to be supplied, how they are handled depends upon the UniformMessages1 implementation, but generally they are injected into the response.

  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def decompose(key: String, args: Any*): A

    Permalink

    Attempt to match against key, if a match is found return it, otherwise attempt to find fallback values by splitting the key into substrings using '.' (full-stop) as a separator.

    Attempt to match against key, if a match is found return it, otherwise attempt to find fallback values by splitting the key into substrings using '.' (full-stop) as a separator.

    val m = UniformMessages.fromMap(
      Map("a1.b1.c1" -> List("Specific"),
          "b1.c1"    -> List("Match2"),
          "c1"       -> List("Very General"))
    )
    
    scala> m.decompose("a1.b1.c1")
    res1: String = "Specific"
    
    scala> m.decompose("amodified.b1.c1")
    res2: String = "Match2"
    
    scala> m.decompose("amodified.bmodified.c1")
    res3: String = "Very General"
    
    scala> m.decompose("nonexistant") // throws exception

    If still no match is found an exception is thrown.

  9. def decomposeOpt(key: String, args: Any*): Option[A]

    Permalink

    Attempt to match against key, if a match is found return it, otherwise attempt to find fallback values by splitting the key into substrings using '.' (full-stop) as a separator.

    Attempt to match against key, if a match is found return it, otherwise attempt to find fallback values by splitting the key into substrings using '.' (full-stop) as a separator.

    val m = UniformMessages.fromMap(
      Map("a1.b1.c1" -> List("Match1"),
          "b1.c1"    -> List("Match2"),
          "c1"       -> List("Match3"))
    )
    scala> m.decomposeOpt("a1.b1.c1")
    res1: Option[String] = Some(Match1)
    
    scala> m.decomposeOpt("amodified.b1.c1")
    res2: Option[String] = Some(Match2)
    
    scala> m.decomposeOpt("amodified.bmodified.c1")
    res3: Option[String] = Some(Match3)
    
    scala> m.decomposeOpt("amodified.bmodified.cmodified")
    res4: Option[String] = None
    
    scala> m.decomposeOpt("a1.b1.cmodified")
    res5: Option[String] = None

    If still no match is found return None.

  10. final def eq(arg0: AnyRef): Boolean

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

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. def get(keys: List[String], args: Any*): Option[A]

    Permalink

    Retrieve a single message against the keys, replacing any arguments with the values supplied.

    Retrieve a single message against the keys, replacing any arguments with the values supplied. Returns None if no message is found against any of the keys. If there are multiple matches the first one will be used.

    keys

    lookup identifiers for the message, each is tried in turn

    args

    any arguments to be supplied, how they are handled depends upon the UniformMessages1 implementation, but generally they are injected into the response.

  14. final def getClass(): Class[_]

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

    Permalink
    Definition Classes
    AnyRef → Any
  16. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  17. def map[B](f: (A) ⇒ B): UniformMessages[B]

    Permalink
  18. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  19. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  20. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  21. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  22. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  23. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. def withCustomContent(customContent: Map[String, (String, List[Any])]): UniformMessages[A]

    Permalink
  27. def withDefault(f: (String) ⇒ A): UniformMessages[A]

    Permalink

    provides another instance using a fallback function.

    provides another instance using a fallback function.

    As a consequence this should never throw a NoSuchElementException.

    scala> val m = UniformMessages.noop[Int].withDefault(_.size)
    m: ltbs.uniform.UniformMessages[Int] = ...
    
    scala> m.get("non-existant")
    res0: Option[Int] = None
    
    scala> m("non-existant")
    res1: Int = 12

Inherited from AnyRef

Inherited from Any

Ungrouped