Class: Ability
- Inherits:
-
Object
- Object
- Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/ability.rb,
lib/generators/templates/cancan/ability.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all_aces_for(user) ⇒ Object
- #init_wheels(user) ⇒ Object
-
#initialize(user) ⇒ Ability
constructor
A new instance of Ability.
Constructor Details
#initialize(user) ⇒ Ability
Returns a new instance of Ability.
12 13 14 15 16 17 18 19 |
# File 'app/models/ability.rb', line 12 def initialize(user) user ||= User.nobody puts all_aces_for(user).map{|t| "#{t.resource_type} #{t..inspect}"}.join("\n") self.class.initializers.each{|t| self.send(t, user)} all_aces_for(user).each do |ace| ace.configure(self) end end |
Class Method Details
.initializer(*method_names) ⇒ Object
7 8 9 |
# File 'app/models/ability.rb', line 7 def self.initializer(*method_names) method_names.each{|t| initializers << t} end |
.initializers ⇒ Object
3 4 5 |
# File 'app/models/ability.rb', line 3 def self.initializers @initializers ||= [] end |
Instance Method Details
#all_aces_for(user) ⇒ Object
21 22 23 |
# File 'app/models/ability.rb', line 21 def all_aces_for(user) (user.access_control_entries + user.role.access_control_entries) end |
#init_wheels(user) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/ability.rb', line 25 def init_wheels(user) can :read, :all roles = Role.all def roles.find_by_name(name); self.select{|t| t.name==name}[0]; end; case user.role.id when roles.find_by_name("Super").id can :manage, :all when roles.find_by_name("Admin").id can :manage, :all when roles.find_by_name("User").id can :manage, Gallery, :user_id => user.id can :manage, Blog, :user_id => user.id can :edit, Profile, :user_id => user.id cannot :read, User can :edit, User, :id => user.id end end |