Sha256: 3c2822a164c64d639551a8494c8effe3bcace7c1030d9ff9e1e159e667b8879a

Contents?: true

Size: 554 Bytes

Versions: 7

Compression:

Stored size: 554 Bytes

Contents

module Rostra
  class Ability
    include CanCan::Ability

    attr_reader :user

    def initialize(user)
      @user = user || User.new

      if logged_in?
        can :manage, Question, :user => user
        can :manage, Answer, :user => user
        can :manage, Comment, :user => user

        can :vote, Question
        cannot :vote, Question, :user => user

        can :vote, Answer
        cannot :vote, Answer, :user => user
      end

      can :read, :all
    end

    private

    def logged_in?
      ! user.new_record?
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rostra-0.0.10 app/models/rostra/ability.rb
rostra-0.0.9 app/models/rostra/ability.rb
rostra-0.0.8 app/models/rostra/ability.rb
rostra-0.0.7 app/models/rostra/ability.rb
rostra-0.0.6 app/models/rostra/ability.rb
rostra-0.0.5 app/models/rostra/ability.rb
rostra-0.0.4 app/models/rostra/ability.rb