Class: RolePermit::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/permits.rb,
lib/generators/auth_assist/test.rb,
lib/generators/auth_assist/templates/permits.rb

Direct Known Subclasses

Admin, Author, Moderator, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ability) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/permits.rb', line 6

def initialize(ability)
  @ability = ability
end

Instance Attribute Details

#abilityObject

Returns the value of attribute ability.



4
5
6
# File 'lib/permits.rb', line 4

def ability
  @ability
end

Instance Method Details

#can(action, subject, conditions = nil, &block) ⇒ Object



10
11
12
# File 'lib/permits.rb', line 10

def can(action, subject, conditions = nil, &block)
  ability.can(action, subject, conditions, &block)
end

#cannot(action, subject, conditions = nil, &block) ⇒ Object



14
15
16
# File 'lib/permits.rb', line 14

def cannot(action, subject, conditions = nil, &block)
  ability.cannot(action, subject, conditions, &block)
end

#owns(user, clazz, field = :user_id) ⇒ Object



18
19
20
21
22
# File 'lib/permits.rb', line 18

def owns(user, clazz)
  can :manage, clazz do |comment|
    comment.try(:user) == user || comment.try(:owner) == user
  end                
end

#permit?(user, request) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/permits.rb', line 24

def permit?(user)    
  user.has ability      
end