Created
April 20, 2012 09:01
-
-
Save kfatehi/2427227 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
module UserAbilities | |
def can?(verb, target) | |
Ability[verb].call(self, verb, target) | |
end | |
Ability = { | |
:use=>lambda { |user, verb, target| | |
# This depends primarily on what the target is. | |
Target[target.class.to_s].call(user, verb, target) | |
} | |
} | |
Target = { | |
"Folder"=>lambda {|user, verb, target_folder| | |
user.folders.exists? target_folder | |
}, | |
"User"=>lambda {|user, verb, target_user| | |
# "Power users" could set advanced permissions | |
# through a domain-specific language we come up with | |
# that gets injected in this space, so to speak | |
} | |
} | |
end | |
class User | |
include UserAbilities | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment