Class: Ability

Inherits:
Object
  • Object
show all
Includes:
CanCanNamespace::Ability
Defined in:
lib/generators/freeberry/models/templates/models/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/freeberry/models/templates/models/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/freeberry/models/templates/models/ability.rb', line 4

def context
  @context
end

#userObject

Returns the value of attribute user.



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

def user
  @user
end

Instance Method Details

#adminObject



33
34
35
36
37
38
39
# File 'lib/generators/freeberry/models/templates/models/ability.rb', line 33

def admin
  can :manage, :all
  can :manage, :all, :context => :manage
  
  can [:create, :destroy], Comment
  can :update, Comment, :user_id => @user.id
end

#defaultObject



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

def default
  can :create, Comment
  can [:update, :destroy], Comment, :user_id => @user.id, :newly_created? => true
end

#moderatorObject



29
30
31
# File 'lib/generators/freeberry/models/templates/models/ability.rb', line 29

def moderator
  # TODO
end

#redactorObject



25
26
27
# File 'lib/generators/freeberry/models/templates/models/ability.rb', line 25

def redactor
  # TODO
end