Class: Auth::Role

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (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_rolesObject

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