-
Notifications
You must be signed in to change notification settings - Fork 18
Home
randx edited this page Aug 13, 2011
·
36 revisions
gem install six
class BookRules
def self.allowed(author, book)
rules = []
rules << :read_book if book.published?
rules << :edit_book if author.id == book.author_id
rules
end
end
Six::Guard.instance.add_pack(:book, BookRules)
Six::Guard.instance.allowed? :read_book, nil, nil # false
Six::Guard.instance.allowed? :read_book, nil, published_book # true
Six::Guard.instance.allowed? :edit_book, nil, nil # false
Six::Guard.instance.allowed? :edit_book, author, author.books.first # true