Created
August 17, 2014 08:49
-
-
Save aishek/62b2ee12f201e87ff396 to your computer and use it in GitHub Desktop.
gem six basic usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) Для экземпляров класса Purchase задаём правила, | |
# по которым определяем доступные над ними | |
# действия. В нашем случае разрешаем всем :create | |
class Purchase | |
def allowed(object, subject) | |
rules = [] | |
return rules unless subject.kind_of?(Purchase) | |
rules << :create | |
rules | |
end | |
end | |
# 2) Создаём объект abilities... | |
abilities = Six.new | |
# ...и добавляем в него субъект, для которого | |
# будем проверять разрешённые действия. | |
purchase = Purchase.new | |
abilities << purchase | |
# 3) Проверяем, разрешено ли текущему пользователю делать | |
# :create над объектом purchase | |
abilities.allowed?(current_user, :create, purchase) # true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment