Class: Ability

Inherits:
Object
  • Object
show all
Includes:
CanCanNamespace::Ability
Defined in:
lib/generators/sunrise/templates/models/defaults/ability.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, context = nil) ⇒ Ability

Returns a new instance of Ability.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 6

def initialize(user, context = nil)
  alias_action :delete, :to => :destroy

  @user = (user || User.new) # guest user (not logged in)
  @context = context
  
  case @user.role_type_id
    when RoleType.default.id then default
    when RoleType.redactor.id then redactor
    when RoleType.moderator.id then moderator
    when RoleType.admin.id then admin
  end
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



4
5
6
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 4

def context
  @context
end

#userObject

Returns the value of attribute user.



4
5
6
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 4

def user
  @user
end

Instance Method Details

#adminObject



32
33
34
35
36
37
38
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 32

def admin
  can :manage, :all
  can :manage, :all, :context => :manage
  
  # User cannot destroy self account
  cannot :destroy, User, :id => @user.id, :context => :manage
end

#defaultObject



20
21
22
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 20

def default
  # TODO
end

#moderatorObject



28
29
30
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 28

def moderator
  # TODO
end

#redactorObject



24
25
26
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 24

def redactor
  # TODO
end