lib/trust/permissions.rb
def can(*args)
        options = args.extract_options!
        enforce = options.delete(:enforce)
        p = expand_aliases(args).collect { |action| [action, options] }
        if @in_role_block
          @perms[:can] += p
          if enforce
            @perms[:cannot] = expand_aliases(args).collect { |action| action }
          end
        else
          @@can_expressions += 1
          perms = {:can => p }
          if enforce
            perms[:cannot] = expand_aliases(args).collect { |action| action }
          end
          return perms
        end
      end
# Defines permissions
#
# === Arguments
#
#   action - can be an alias or an actions of some kind
#   options - control the behavior of the permission
#
# === Options
#   +:if/:unless+ - :symbol or proc that will be called to evaluate an expression
#   +enforce+ - set to true to enforce the permission, delete any previous grants given from parent classes. Most meaningful in
#               combination with +:if+ and +:unless+ options
#
# === Example
#
#   module Permissions
#     class Account < Trust::Permissions
#       role :admin, :accountant do 
#         can :read
#         can :update, :unless => :closed?
#       end
#     end
#   end
# 
# The above permits admin and accountant to read accounts, but can update only if the account is not closed.
# In the example above a method is used to test data on the actual record when testing for permissions.
Defines permissions
Arguments

can be an alias or an actions of some kind
options - control the behavior of the permission

Options
+:if/:unless+ - :symbol or proc that will be called to evaluate an expression
+enforce+ - set to true to enforce the permission, delete any previous grants given from parent classes. Most meaningful in
combination with +:if+ and +:unless+ options

Example



The above permits admin and accountant to read accounts, but can update only if the account is not closed.
In the example above a method is used to test data on the actual record when testing for permissions.
Defines permissions Arguments can be an alias or an actions of some kind options - control the behavior of the permission Options + : if / : unless + - : symbol or proc that will be called to evaluate an expression + enforce + - set to true to enforce the permission delete any previous grants given from parent classes . Most meaningful in combination with + : if + and + : unless + options Example The above permits admin and accountant to read accounts but can update only if the account is not closed . In the example above a method is used to test data on the actual record when testing for permissions .
def can(*args)
        options = args.extract_options!
        enforce = options.delete(:enforce)
        p = expand_aliases(args).collect { |action| [action, options] }
        if @in_role_block
          @perms[:can] += p
          if enforce
            @perms[:cannot] = expand_aliases(args).collect { |action| action }
          end
        else
          @@can_expressions += 1
          perms = {:can => p }
          if enforce
            perms[:cannot] = expand_aliases(args).collect { |action| action }
          end
          return perms
        end
      end
def can ( * args ) options = args . extract_options! enforce = options . delete ( :enforce ) p = expand_aliases ( args ) . collect { | action | [ action , options ] } if @in_role_block @perms [ :can ] += p if enforce @perms [ :cannot ] = expand_aliases ( args ) . collect { | action | action } end else @@can_expressions += 1 perms = { :can => p } if enforce perms [ :cannot ] = expand_aliases ( args ) . collect { | action | action } end return perms end end
Defines permissions
 Arguments
Defines permissions Arguments
args