Class: Authorization::Engine
- Inherits:
-
Object
- Object
- Authorization::Engine
- Defined in:
- lib/declarative_authorization_padrino/authorization.rb
Instance Method Summary collapse
-
#roles_for(user) ⇒ Object
Returns the role symbols of the given user.
Instance Method Details
#roles_for(user) ⇒ Object
Returns the role symbols of the given user.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/declarative_authorization_padrino/authorization.rb', line 10 def roles_for (user) user ||= Authorization.current_user raise AuthorizationUsageError, "User object doesn't respond to roles (#{user.inspect})" \ if !user.respond_to?(:role_symbols) and !user.respond_to?(:roles) ::Padrino.logger.info("The use of user.roles is deprecated. Please add a method " + "role_symbols to your User model.") if defined?(::Padrino) and ::Padrino.respond_to?(:logger) and !user.respond_to?(:role_symbols) roles = user.respond_to?(:role_symbols) ? user.role_symbols : user.roles raise AuthorizationUsageError, "User.#{user.respond_to?(:role_symbols) ? 'role_symbols' : 'roles'} " + "doesn't return an Array of Symbols (#{roles.inspect})" \ if !roles.is_a?(Array) or (!roles.empty? and !roles[0].is_a?(Symbol)) (roles.empty? ? [Authorization.default_role] : roles) end |