Module: Coyote::Membership
- Defined in:
- lib/coyote/membership.rb
Overview
Utility functions for managing Organizational Roles
Constant Summary collapse
- ROLES =
Enumerates the roles available in the Postgres 'user_role' ENUM, for use with ActiveRecord::Base.enum
{ guest: 'guest', viewer: 'viewer', author: 'author', editor: 'editor', admin: 'admin', owner: 'owner' }.freeze
Class Method Summary collapse
-
.each_role {|role_human_name, role_name, role_rank| ... } ⇒ Object
Iterates through all possible Membership roles.
-
.role_names ⇒ Array<Symbol>
List of role names.
-
.role_rank(role_name) ⇒ Integer
For sorting and comparison purposes; higher numbers are associated with higher-ranking/more-powerful roles.
Class Method Details
.each_role {|role_human_name, role_name, role_rank| ... } ⇒ Object
Iterates through all possible Membership roles
20 21 22 23 24 |
# File 'lib/coyote/membership.rb', line 20 def self.each_role ROLES.each_key do |role_name| yield role_name.to_s.titleize, role_name, role_rank(role_name) if block_given? end end |
.role_names ⇒ Array<Symbol>
Returns list of role names
27 28 29 |
# File 'lib/coyote/membership.rb', line 27 def self.role_names ROLES.keys end |
.role_rank(role_name) ⇒ Integer
Returns for sorting and comparison purposes; higher numbers are associated with higher-ranking/more-powerful roles
32 33 34 35 |
# File 'lib/coyote/membership.rb', line 32 def self.role_rank(role_name) return role_names.size + 1 if role_name == :staff role_names.index(role_name.to_sym) || -1 end |