File: book_rules.rb

package info (click to toggle)
ruby-six 0.2.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 196 kB
  • sloc: ruby: 295; makefile: 6
file content (14 lines) | stat: -rw-r--r-- 435 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class BookRules
  def allowed(author, book)
    # check for correct class & nil
    return [] unless author.instance_of?(Author) && book.instance_of?(Book)

    rules = []
    rules << :read_book if book.public || book.author?(author)
    rules << :rate_book if book.public && !book.author?(author)
    rules << :edit_book if book.author?(author)
    rules << :publish_book if book.author?(author) && !book.public
    rules
  end
end