Sha256: 6ab36e1802d2b232c743e906ae9895797060c8b5ce9e7c044b6ca14a6f99c14a

Contents?: true

Size: 829 Bytes

Versions: 1

Compression:

Stored size: 829 Bytes

Contents

module RailsBlogEngine
  class Ability
    include CanCan::Ability

    def initialize(user)
      can_read_blog
      if user && blog_admin?(user)
        can_manage_blog
      end
    end

    protected

    def blog_admin?(user)
      method = Rails.configuration.rails_blog_engine.blog_admin_method
      if user.respond_to?(method)
        user.send(method)
      else
        raise "You must define #{method} on your user model, as described in README.md"
      end
    end

    def can_read_blog
      can :read, RailsBlogEngine::Post
      can [:read, :create], RailsBlogEngine::Comment
    end

    def can_manage_blog
      alias_action :mark_as_spam, :to => :update
      alias_action :mark_as_ham, :to => :update

      can :manage, RailsBlogEngine::Post
      can :update, RailsBlogEngine::Comment
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_blog_engine-0.0.4 app/models/rails_blog_engine/ability.rb