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
convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
Methods included from Warren::BroadcastMessages
#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren
Class Method Details
.keys ⇒ Object
22 23 24 |
# File 'app/models/role.rb', line 22 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.
43 44 45 46 47 48 49 50 |
# File 'app/models/role.rb', line 43 def (check) case check when nil then true when Class then .is_a?(check) else check == end end |
#destroy_if_empty ⇒ Object
26 27 28 |
# File 'app/models/role.rb', line 26 def destroy_if_empty destroy if users.empty? end |
#touch_authorizable ⇒ Object
30 31 32 |
# File 'app/models/role.rb', line 30 def &.touch # rubocop:disable Rails/SkipsModelValidations end |