Class: Ability
Instance Method Summary collapse
-
#initialize(object = nil) ⇒ Ability
constructor
A new instance of Ability.
Constructor Details
#initialize(object = nil) ⇒ Ability
Returns a new instance of Ability.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ability.rb', line 5 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 |