Sha256: 2e57a5e8293edda4af01c4043cc5e1ebd5f30ec6d338641938a00a58869f0319
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 KB
Contents
require_relative('../reuser') module ReUser class NoRoleError < StandardError; end; class NoDefaultRoleError < StandardError; end; instance_eval do def included(subclass) subclass.instance_eval do @@roles = {} def roles(&block) @@roles ||= {} yield if block @@roles.freeze @@roles.keys end def role(name, actions_list = nil, &block) @@roles[name] ||= ReUser::Role.new(name) role_name = @@roles[name] yield(role_name) if block if actions_list role_name.can(*actions_list) end role_name end def default(name = nil) if name @@roles[:default] = @@roles[name] else @@roles[:default] end end end subclass.class_eval do def role?(name) @role == self.class.role(name) end def can?(name) !!@role.can?(name) end def cant?(name) !@role.can?(name) end def could?(name, obj) @role.could?(name, obj) end def couldnt?(name, obj) !@role.could?(name, obj) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
reuser-0.2.2 | lib/reuser/reuser.rb |
reuser-0.2.1 | lib/reuser/reuser.rb |