Sha256: 0df771472c68a96a0ebe05ee313e47ab5854260724562801ebd16ee1830635de

Contents?: true

Size: 891 Bytes

Versions: 9

Compression:

Stored size: 891 Bytes

Contents

class Ability
  include CanCan::Ability
  initializer :init_wheels

  def initialize(user)
    initializers.each{|t| self.send(t, user)}
  end

  def init_wheels(user)
    can :read, :all
    return cannot :read, User unless user
    roles = Role.all
    user ||= User.new
    def roles.find_by_name(name); self.select{|t| t.name==name}[0]; end;
    case user.role_id
      when roles.find_by_name("Super")
        can :manage, :all
      when roles.find_by_name("Admin")
        can :manage, :all
      when roles.find_by_name("User")
        can :manage, Gallery, :user_id => user.id
        can :manage, Blog, :user_id => user.id
        can :edit, Profile, :user_id => user.id
        cannot :read, User
    end
    can :read, :all
  end


  def self.initializer(*method_names)
    method_names.each{|t| initializers << t}
  end

  def initializers
    @initializers ||= []
  end


end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
wheels-0.0.26 app/models/ability.rb
wheels-0.0.25 app/models/ability.rb
wheels-0.0.24 app/models/ability.rb
wheels-0.0.23 app/models/ability.rb
wheels-0.0.22 app/models/ability.rb
wheels-0.0.21 app/models/ability.rb
wheels-0.0.20 app/models/ability.rb
wheels-0.0.19 app/models/ability.rb
wheels-0.0.18 app/models/ability.rb