Module: Securial::Helpers::RolesHelper

Extended by:
RolesHelper
Included in:
RolesHelper
Defined in:
lib/securial/helpers/roles_helper.rb

Overview

Helper methods for role management and formatting.

This module provides utility methods for working with user roles, including namespace generation for protected routes and role name formatting for user interfaces. It centralizes role-related logic to ensure consistent behavior across the application.

Instance Method Summary collapse

Instance Method Details

#protected_namespaceString

Generates a namespace string for protected admin routes.

Converts the configured admin role into a pluralized, underscored namespace suitable for use in Rails routing and controller organization. This ensures admin routes are consistently organized under the appropriate namespace.

Examples:

With default admin role

# When Securial.configuration.admin_role = :admin
protected_namespace
# => "admins"

With custom admin role

# When Securial.configuration.admin_role = :super_admin
protected_namespace
# => "super_admins"

With spaced role name

# When Securial.configuration.admin_role = "Site Administrator"
protected_namespace
# => "site_administrators"

Returns:

  • (String)

    The pluralized, underscored admin role namespace



53
54
55
# File 'lib/securial/helpers/roles_helper.rb', line 53

def protected_namespace
  Securial.configuration.admin_role.to_s.strip.underscore.pluralize
end

#titleized_admin_roleString

Formats the admin role name for user interface display.

Converts the configured admin role into a human-readable, title-cased string suitable for display in user interfaces, form labels, and user-facing messages.

Examples:

With default admin role

# When Securial.configuration.admin_role = :admin
titleized_admin_role
# => "Admin"

With underscored role name

# When Securial.configuration.admin_role = :super_admin
titleized_admin_role
# => "Super Admin"

With already formatted role

# When Securial.configuration.admin_role = "Site Administrator"
titleized_admin_role
# => "Site Administrator"

Returns:

  • (String)

    The title-cased admin role name



80
81
82
# File 'lib/securial/helpers/roles_helper.rb', line 80

def titleized_admin_role
  Securial.configuration.admin_role.to_s.strip.titleize
end