Class: Alchemy::Permissions

Inherits:
Object
  • Object
show all
Includes:
AdminUser, AuthorUser, EditorUser, GuestUser, MemberUser, CanCan::Ability
Defined in:
lib/alchemy/permissions.rb

Overview

## Alchemy’s permissions

These are CanCan abilities, but to prevent any naming collusions we named it permissions.

Alchemy user rules are modules that can be included in your app’s/engine’s Ability class.

### Example:

# app/models/ability.rb
class Ability
  include CanCan::Ability
  include Alchemy::Permissions::EditorUser

  def initialize(user)
    return if user.nil?
    @user ||= user
    if @user.has_role?(:demo)
      alchemy_editor_rules # alchemy editor roles
      # your own rules
    end
  end
end

Defined Under Namespace

Modules: AdminUser, AuthorUser, EditorUser, GuestUser, MemberUser

Instance Method Summary collapse

Methods included from AdminUser

#alchemy_admin_rules

Methods included from EditorUser

#alchemy_editor_rules

Methods included from AuthorUser

#alchemy_author_rules

Methods included from MemberUser

#alchemy_member_rules

Methods included from GuestUser

#alchemy_guest_user_rules

Constructor Details

#initialize(user) ⇒ Permissions

Returns a new instance of Permissions.



30
31
32
33
34
# File 'lib/alchemy/permissions.rb', line 30

def initialize(user)
  set_action_aliases
  @user ||= user
  @user ? user_role_rules : alchemy_guest_user_rules
end