Class: Ability::Roles
- Inherits:
-
Object
- Object
- Ability::Roles
- Defined in:
- app/models/ability.rb
Instance Attribute Summary collapse
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Instance Method Summary collapse
- #has_role?(rolename) ⇒ Boolean
-
#initialize(user, zone = nil) ⇒ Roles
constructor
A new instance of Roles.
Constructor Details
#initialize(user, zone = nil) ⇒ Roles
Returns a new instance of Roles.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/ability.rb', line 10 def initialize(user, zone = nil) @roles = [] #Runtime roles zone ||= SITE_DEFAULT @roles << Role.find_by_name(zone) user ||= User.new # guest user (not logged in) @roles += user.roles user.groups.each { |group| @roles += group.roles } @roles.sort!.uniq! end |
Instance Attribute Details
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
8 9 10 |
# File 'app/models/ability.rb', line 8 def roles @roles end |
Instance Method Details
#has_role?(rolename) ⇒ Boolean
23 24 25 |
# File 'app/models/ability.rb', line 23 def has_role?(rolename) roles.any? { |role| role.name == rolename.to_s } end |