Class: Auth::Role
- Inherits:
-
Object
- Object
- Auth::Role
- Defined in:
- lib/nitro/auth/model/user.rb
Overview
Represents a (simple) security role.
Many-to-many with Auth::User. An Auth::User can have many
Roles and an Auth::Role can be had by many Users.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The role name.
Instance Method Summary collapse
-
#create_roles ⇒ Object
Create the admin and user roles.
-
#initialize(name) ⇒ Role
constructor
Note that if you subclass Auth::Role, you need to allow just passing in a role name and nothing else in your initialize (and your schema), or you need to override the create_roles method.
Constructor Details
#initialize(name) ⇒ Role
Note that if you subclass Auth::Role, you need to allow just passing in a role name and nothing else in your initialize (and your schema), or you need to override the create_roles method.
134 135 136 |
# File 'lib/nitro/auth/model/user.rb', line 134 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
The role name. (Must be unique.)
120 121 122 |
# File 'lib/nitro/auth/model/user.rb', line 120 def name @name end |
Instance Method Details
#create_roles ⇒ Object
Create the admin and user roles.
139 140 141 142 143 144 145 |
# File 'lib/nitro/auth/model/user.rb', line 139 def create_roles # I believe that because this is called in an advice, # that self.class will be the right class for the entity # that actually got created, even if it's not us. self.class.create(Auth.admin_role) if 0 == self.class.count(:condition => "name = '#{Auth.admin_role}'") self.class.create(Auth.user_role) if 0 == self.class.count(:condition => "name = '#{Auth.user_role}'") end |