Class: Ability
- Inherits:
-
Object
- Object
- Ability
- Includes:
- CanCanNamespace::Ability
- Defined in:
- lib/generators/sunrise/templates/models/defaults/ability.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #admin ⇒ Object
- #default ⇒ Object
-
#initialize(user, context = nil) ⇒ Ability
constructor
A new instance of Ability.
- #moderator ⇒ Object
- #redactor ⇒ Object
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
#context ⇒ Object
Returns the value of attribute context.
4 5 6 |
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 4 def context @context end |
#user ⇒ Object
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
#admin ⇒ Object
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 |
#default ⇒ Object
20 21 22 |
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 20 def default # TODO end |
#moderator ⇒ Object
28 29 30 |
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 28 def moderator # TODO end |
#redactor ⇒ Object
24 25 26 |
# File 'lib/generators/sunrise/templates/models/defaults/ability.rb', line 24 def redactor # TODO end |