Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. sealed abstract class ShowUnapproved {
  2. def shallShow(post: Post): Boolean // a "post" is e.g. a comment
  3. }
  4.  
  5.  
  6. object ShowUnapproved {
  7.  
  8. case object None extends ShowUnapproved {
  9. override def shallShow(post: Post) =
  10. post.someVersionApproved
  11. }
  12.  
  13. case object All extends ShowUnapproved {
  14. override def shallShow(post: Post) = true
  15. }
  16.  
  17. case class WrittenByUser(userId: String) extends ShowUnapproved {
  18. override def shallShow(post: Post) =
  19. post.userId == userId
  20. }
  21. }
  22.  
  23. PageReneder.renderPage(page, ShowUnapproved.All)
  24. PageReneder.renderPage(page, ShowUnapproved.WrittenByUser(userId))
  25.  
  26. val showUnapproved = ... // sounds like a Boolean but it is not
  27.  
  28. val anyPendingApprovalText: NodeSeq =
  29. if (showUnapproved.shallShow(post)) makePendingApprovalText(post)
  30. else Nil
  31. // does `showUnapproved.shallShow` above sound good to you?
  32.  
  33. sealed abstract class CommentVisibility {
  34. def shallShow(comment: Comment): Boolean
  35. }
  36.  
  37. object CommentVisibility {
  38. case object HideUnapproved
  39. case object ShowUnapproved
  40. case class ShowAllByUser(userId)
  41. }
  42.  
  43. renderPage(page, CommentVisibility.ShowUnapproved)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement