-
Notifications
You must be signed in to change notification settings - Fork 1
Print all defined rules
Adam Pahlevi Baihaqi edited this page Sep 26, 2015
·
2 revisions
Rules that is defined can be printed by making call to Bali::Printer
.
For example, if we have rules defined as follow:
Bali.map_rules do
rules_for My::Transaction do
describe(:supreme_user) { can_all }
describe(:admin) do
can_all
cannot :delete
end
describe :finance do
can :view, :print
can :edit, :save
end
others do
can :view, if: proc { |txn| txn.is_settled? }
end
end
rules_for My::SecuredTransaction, inherits: My::Transaction do
describe :finance do
clear_rules
can :view
end
end # rules for My::SecuredTransaction
end
We can print all defined rules by calling:
Bali.pretty_print
Output:
===== My::Transaction =====
Supreme_user, can all: true, cannot all: false
--------------------------------------------------------------------------------
1. Supreme_user can do anything except if explicitly stated otherwise
Admin, can all: true, cannot all: false
--------------------------------------------------------------------------------
1. Admin can do anything except if explicitly stated otherwise
2. Admin cannot delete My::Transaction
Finance, can all: false, cannot all: false
--------------------------------------------------------------------------------
1. Finance can view My::Transaction
2. Finance can print My::Transaction
3. Finance can edit My::Transaction
4. Finance can save My::Transaction
Others, can all: false, cannot all: false
--------------------------------------------------------------------------------
1. Others can view My::Transaction, with condition
===== My::SecuredTransaction =====
Supreme_user, can all: true, cannot all: false
--------------------------------------------------------------------------------
1. Supreme_user can do anything except if explicitly stated otherwise
Admin, can all: true, cannot all: false
--------------------------------------------------------------------------------
1. Admin can do anything except if explicitly stated otherwise
2. Admin cannot delete My::SecuredTransaction
Finance, can all: false, cannot all: false
--------------------------------------------------------------------------------
1. Finance can view My::SecuredTransaction
Others, can all: false, cannot all: false
--------------------------------------------------------------------------------
1. Others can view My::SecuredTransaction, with condition
Printed at 26-09-2015 12:58PM +07:00