lib/reuser/reuser.rb in reuser-0.2.2 vs lib/reuser/reuser.rb in reuser-1.0.0

- old
+ new

@@ -4,11 +4,10 @@ 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 @@ -21,38 +20,26 @@ 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) + def can?(action) + !!@role.can?(action) end - def can?(name) - !!@role.can?(name) + def cant?(action) + !@role.can?(action) end - def cant?(name) - !@role.can?(name) + def could?(action, obj) + !!@role.could?(action, obj) end - def could?(name, obj) - @role.could?(name, obj) - end - - def couldnt?(name, obj) - !@role.could?(name, obj) + def couldnt?(action, obj) + !@role.could?(action, obj) end end end end end