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

- old
+ new

@@ -1,2 +1,37 @@ -require_relative(reuser_file = './reuser/reuser') -require_relative(role_file = './reuser/role') +require_relative "./reuser/role" + +module ReUser + + def self.included klass + + klass.instance_eval do + def roles &block + @@roles ||= {} + yield if block_given? + @@roles.freeze.keys + end + + def role name, permissions=[], &block + role = ( @@roles[name] ||= ReUser::Role.new(name, permissions) ) + yield(role) if block_given? + role + end + end + end + + def can? permission + @role.can? permission + end + + def cant? permission + !(can? permission) + end + + def could? permission, block_args + @role.could? permission, block_args + end + + def couldnt? permission, block_args + !(couldnt? permission, block_args) + end +end