Module: Rbacan
- Defined in:
- lib/rbacan.rb,
lib/rbacan/engine.rb,
lib/rbacan/version.rb,
app/models/rbacan/role.rb,
lib/rbacan/permittable.rb,
app/models/rbacan/user_role.rb,
app/models/rbacan/permission.rb,
lib/rbacan/roles_and_permissions.rb,
app/models/rbacan/role_permission.rb,
app/models/rbacan/application_record.rb,
lib/generators/rbacan/install_generator.rb
Defined Under Namespace
Modules: Generators, Permittable, RolesAndPermissions
Classes: ApplicationRecord, Engine, Error, Permission, Role, RolePermission, UserRole
Constant Summary
collapse
- VERSION =
"0.1.2"
- @@permittable_class =
'User'
- @@role_class =
'Rbacan::Role'
- @@role_table =
'roles'
- @@user_role_class =
'Rbacan::UserRole'
- @@user_role_table =
'user_roles'
- @@permission_class =
'Rbacan::Permission'
- @@permission_table =
'permissions'
- @@role_permission_class =
'Rbacan::RolePermission'
- @@role_permission_table =
'role_permissions'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
54
55
56
|
# File 'lib/rbacan.rb', line 54
def self.configure(&block)
yield self
end
|
Instance Method Details
#assign_permission_to_role(role_name, permission_name) ⇒ Object
38
39
40
41
42
|
# File 'lib/rbacan.rb', line 38
def assign_permission_to_role(role_name, permission_name)
chosen_role = @@role_class.find_by_name(role_name)
given_permission = @@permission_class.find_by_name(permission_name)
@@role_permission_class.create(role_id: chosen_role.id, perm_id: given_permission.id)
end
|
#assign_role(role_name) ⇒ Object
44
45
46
47
|
# File 'lib/rbacan.rb', line 44
def assign_role(role_name)
assigned_role = Role.find_by_name(role_name)
@@user_role_class.find_or_create_by(user_id: self.id, role_id: assigned_role.id)
end
|
#create_permission(permission_name) ⇒ Object
34
35
36
|
# File 'lib/rbacan.rb', line 34
def create_permission(permission_name)
@@permission_class.create(name: permission_name)
end
|
#create_role(role_name) ⇒ Object
30
31
32
|
# File 'lib/rbacan.rb', line 30
def create_role(role_name)
@@role_class.create(name: role_name)
end
|
#remove_user_role(role_name) ⇒ Object
49
50
51
52
|
# File 'lib/rbacan.rb', line 49
def remove_user_role(role_name)
removed_role = Role.find_by_name(role_name)
@@user_role_class.where(user_id: self.id, role_id: removed_role.id).destroy_all
end
|