Skip to content

Instantly share code, notes, and snippets.

@wereHamster
Created July 23, 2012 12:58
Show Gist options
  • Save wereHamster/3163506 to your computer and use it in GitHub Desktop.
Save wereHamster/3163506 to your computer and use it in GitHub Desktop.
package models
/* A scope defines what actions a user can perform. Each possible action is
* assigned a bit in a bitset (up to 64 different actions are possible in
* theory, though we only store a limited number of bits in the database).
*/
sealed case class Scope(value: Long) {
/* Combine two scopes. Does a bitwise or of the two bitsets and returns a
* new scope.
*/
def |(x: Scope): Scope =
Scope(this.value | x.value)
/* Return true if `this` includes the given scope. */
def includes(x: Scope): Boolean =
(this.value & x.value) == x.value
}
object Empty extends Scope(0)
object All extends Scope(0xFFFFFFFF)
object Read extends Scope(1)
object Write extends Scope(2)
object Query extends Scope(4)
@wereHamster
Copy link
Author

I was hoping to hide the implementation detail and only expose the Scope type and the instances.

@meiersi
Copy link

meiersi commented Jul 24, 2012

OK. I was just reacting to the comments on the public methods, which described the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment