Created
July 23, 2012 12:58
-
-
Save wereHamster/3163506 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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) |
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
I was hoping to hide the implementation detail and only expose the
Scope
type and the instances.