Sha256: fec72d7839d0bc2d761aed0789fead59e8f60b0706e94abfe9ac223f0eaea848
Contents?: true
Size: 1.1 KB
Versions: 37
Compression:
Stored size: 1.1 KB
Contents
class UserRole < ActiveRecord::Base belongs_to :user belongs_to :role serialize :priveleges validates :role, :presence => true def method_missing(method, *args) method = method.to_s if method.starts_with? 'can_' role_keyword = method[method.index('_')+1..method.rindex('_')-1] privelege = method[method.rindex('_')+1..-1] self.priveleges = [] unless self.priveleges.is_a?(Array) if method.ends_with? '=' privelege = privelege[0..-2] if role && role.keyword == role_keyword if args[0] && args[0] != 'false' self.priveleges = (self.priveleges + [privelege]).uniq else self.priveleges = self.priveleges.select{|x| x != privelege} end end else return false if !role || role.keyword != role_keyword self.priveleges.include?(privelege) end else super(method.to_sym, *args) end end def respond_to?(method, *args) return true if method.to_s.starts_with? 'can_' super end def priveleged?(privelege) priveleges.include?(privelege.to_s) end end
Version data entries
37 entries across 37 versions & 1 rubygems