Skip to content

Instantly share code, notes, and snippets.

@ahawkins
Created July 1, 2009 23:11
Show Gist options
  • Save ahawkins/139140 to your computer and use it in GitHub Desktop.
Save ahawkins/139140 to your computer and use it in GitHub Desktop.
module KeepUp
module Permissions
module CommonMethods
def self.included(klass)
klass.class_eval do
alias :authorize :grant
end
end
def grant(perm)
perm = perm.to_s if perm.is_a? Symbol
raise "Permission (#{perm}) does not exist" unless self.permission.respond_to? perm.to_sym
self.permission.update_attribute(perm,true)
end
def deauthorize perm
perm = perm.to_s if perm.is_a? Symbol
raise "Permission (#{perm}) does not exist" unless self.permission.respond_to? perm.to_sym
self.permission.update_attribute(perm,false)
end
def cannot? perm
!has_permission? perm
end
def god?
has_permission? :god
end
def has_any_permissions?
true
end
def has_local_permission? perm
return false if self.permission.nil?
return true if self.permission.god
perm = perm.to_s if perm.is_a? Symbol
raise "Permission (#{perm}) does not exist" unless self.permission.respond_to? perm.to_sym
self.permission.send(perm)
end
private
def create_new_permission
self.permission = Permission.create
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment