Class: ArRole
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ArRole
- Defined in:
- app/models/ar_role.rb
Overview
Schema information
Table name: ar_role : User roles
id Integer id created_at Time created_at updated_at Time updated_at name String Role name system_name String System role name if required by application active Boolean Role is active
Documents in this model define all available user roles in the application. Roles are defined by unique name which is valid for current application or as alternative name (system_name) which can be persistent, when application is used as Rails plugin.
Class Method Summary collapse
-
.choices_for_roles ⇒ Object
Return all defined roles as choices for use in select field.
-
.get_role(name) ⇒ Object
Search for role when role parameter is String.
Instance Method Summary collapse
-
#cache_clear ⇒ Object
Clear cache if cache is configured.
Class Method Details
.choices_for_roles ⇒ Object
Return all defined roles as choices for use in select field.
60 61 62 |
# File 'app/models/ar_role.rb', line 60 def self.choices_for_roles where(active: true).order(name: :asc).map { |role| [ role.name, role.id] } end |
.get_role(name) ⇒ Object
Search for role when role parameter is String.
67 68 69 70 71 72 73 |
# File 'app/models/ar_role.rb', line 67 def self.get_role(name) record = Agile.cache_read(['ar_role', name]) return record if record record = find_by(name: name) || find_by(system_name: name) Agile.cache_write(['ar_policy_role', name], record) end |
Instance Method Details
#cache_clear ⇒ Object
Clear cache if cache is configured
51 52 53 54 55 |
# File 'app/models/ar_role.rb', line 51 def cache_clear Agile.cache_clear(:ar_permission) Agile.cache_clear(:ar_site) Agile.cache_clear(:ar_role) end |