Sha256: efb285b20935e1e7a4253abdfead5e87544d67a27652ae8ec64c0c8d36c3a117
Contents?: true
Size: 852 Bytes
Versions: 4
Compression:
Stored size: 852 Bytes
Contents
class Ability include CanCan::Ability def initialize(object=nil) # If a user was passed set the user from it. @user = object.is_a?(Account) ? object.user : object if @user # Add the base user abilities. load_abilities @user.class.name.underscore.to_sym else # If user not set then lets create a guest @user = Object.new load_abilities :guest end # If user has roles get those abilities if @user.respond_to?(:roles) # Add roles on top of the base user abilities @user.roles.each { |role| load_abilities(role) } end end private def user @user end def ability_definitions Canard.ability_definitions end def load_abilities(role) instance_eval(&ability_definitions[role]) if ability_definitions.has_key?(role) end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
canard-0.2.0 | lib/ability.rb |
canard-0.1.2 | lib/ability.rb |
canard-0.1.1 | lib/ability.rb |
canard-0.1.0 | lib/ability.rb |