Class: Role
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Role
- Defined in:
- app/models/role.rb
Overview
Defines named roles for users that may be applied to objects in a polymorphic fashion. For example, you could create a role “moderator” for an instance of a model (i.e., an object), a model class, or without any specification at all.
Defined Under Namespace
Modules: Authorized, UserRoleHelper Classes: UserRole
Class Method Summary collapse
Instance Method Summary collapse
-
#authorizes?(check) ⇒ <Type>
Returns the true if the role authorizes check.
- #destroy_if_empty ⇒ Object
- #touch_authorizable ⇒ Object
Methods inherited from ApplicationRecord
alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
Class Method Details
.keys ⇒ Object
20 21 22 |
# File 'app/models/role.rb', line 20 def self.keys distinct.pluck(:name) end |
Instance Method Details
#authorizes?(check) ⇒ <Type>
Returns the true if the role authorizes check. If check is a class, returns true is the authorizable is that class, otherwise checks the equality.
41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/role.rb', line 41 def (check) case check when nil true when Class .is_a?(check) else check == end end |
#destroy_if_empty ⇒ Object
24 25 26 |
# File 'app/models/role.rb', line 24 def destroy_if_empty destroy if users.empty? end |
#touch_authorizable ⇒ Object
28 29 30 |
# File 'app/models/role.rb', line 28 def &.touch # rubocop:disable Rails/SkipsModelValidations end |