-
Notifications
You must be signed in to change notification settings - Fork 5
Execution modes
kristianmandrup edited this page Apr 15, 2012
·
1 revision
Permits can be configured to be executed in one or more execution modes. The built in modes are:
- cache
- no_cache
The #modes
macro is used to indicate which modes the Permit is executed for. By default, a Permit will be executed for all execution modes.
The following Editor Role Permit will only be executed for the :no_cache
mode.
module Permit::Admin::Role
class Editor < CanTango::Permit::Role
def calc_rules
can :edit, Post if session[:edit_mode]
end
modes :no_cache
end
end
The following code sets up a Permit with a specific namespace (scope) :admin
class AdminAccount < ActiveRecord::Base
class EditorRolePermit < CanTango::Permit::Role
tango_permit :name => :editor, :type => :role, :ns => :admin
def calc_rules
can :edit, Post if session[:edit_mode]
end
modes :no_cache
end
end
Here the tango_permit
macro is used to explicitly configure the Permit with the CanTango Permits system (registry).