Class: Ability
- Inherits:
-
Object
- Object
- Ability
- Includes:
- CanCanNamespace::Ability
- Defined in:
- lib/generators/freeberry/models/templates/models/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/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
#context ⇒ Object
Returns the value of attribute context.
4 5 6 |
# File 'lib/generators/freeberry/models/templates/models/ability.rb', line 4 def context @context end |
#user ⇒ Object
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
#admin ⇒ Object
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 |
#default ⇒ Object
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 |
#moderator ⇒ Object
29 30 31 |
# File 'lib/generators/freeberry/models/templates/models/ability.rb', line 29 def moderator # TODO end |
#redactor ⇒ Object
25 26 27 |
# File 'lib/generators/freeberry/models/templates/models/ability.rb', line 25 def redactor # TODO end |