Skip to content
randx edited this page Aug 13, 2011 · 36 revisions

Six - is a authorization gem for ruby!

Installation

  gem install six

Usage

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

Usage with Rails

  
Clone this wiki locally