Created
March 18, 2011 19:24
-
-
Save paulitex/876678 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalatra.util.MutableMapWithIndifferentAccess | |
import scala.collection.mutable.{ Map => MMap } | |
/** | |
* Provides a Rails/Scalatra like map that sits in the session | |
* and destroys values after the request they were accessed in has returned | |
* | |
* @author paulitex | |
* | |
*/ | |
class Flash extends MutableMapWithIndifferentAccess[Any] { | |
private val map = MMap[String, Any]() | |
private var dirtyKeys: Set[String] = Set() | |
def -=(key: String) = { | |
map -= key | |
this | |
} | |
def +=(kv: (String, Any)) = { | |
map += kv | |
this | |
} | |
def iterator = map.iterator | |
def get(key: String) = { | |
dirtyKeys += key | |
map.get(key) | |
} | |
def sweep() { | |
dirtyKeys.foreach(map -= _) | |
dirtyKeys = Set.empty | |
this | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment