Module: Scimitar::Rbac::RouteHelper

Defined in:
lib/scimitar/rbac/route_helper.rb

Overview

Provides a convenience method for mounting RBAC SCIM resource routes in a Rails application’s routes.rb.

Usage:

# config/routes.rb
Rails.application.routes.draw do
  namespace :scim_v2, path: "scim/v2" do
    mount Scimitar::Engine, at: "/"

    # Mount standard SCIM resources (Users, Groups) manually...

    # Mount all RBAC resources at once:
    Scimitar::Rbac::RouteHelper.mount_rbac_routes(self,
      roles_controller:        "scim_v2/roles",
      entitlements_controller: "scim_v2/entitlements",
      applications_controller: "scim_v2/applications"
    )
  end
end

Class Method Summary collapse

Class Method Details

.mount_rbac_routes(router, **options) ⇒ Object

Mount CRUD routes for all RBAC resources.

Parameters:

  • router (ActionDispatch::Routing::RouteSet)

    The router (pass ‘self` from routes.rb)

  • options (Hash)

    Controller names for each resource

Options Hash (**options):

  • :roles_controller (String)

    Controller for Roles (e.g., “scim_v2/roles”)

  • :entitlements_controller (String)

    Controller for Entitlements

  • :applications_controller (String)

    Controller for Applications



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/scimitar/rbac/route_helper.rb', line 34

def self.mount_rbac_routes(router, **options)
  if options[:roles_controller]
    mount_resource_routes(router, "Roles", options[:roles_controller])
  end

  if options[:entitlements_controller]
    mount_resource_routes(router, "Entitlements", options[:entitlements_controller])
  end

  if options[:applications_controller]
    mount_resource_routes(router, "Applications", options[:applications_controller])
  end
end

.mount_resource_routes(router, resource_name, controller) ⇒ Object

Mount standard SCIM CRUD routes for a single resource.

Parameters:

  • router (ActionDispatch::Routing::RouteSet)

    The router

  • resource_name (String)

    The SCIM resource path (e.g., “Roles”)

  • controller (String)

    The controller name (e.g., “scim_v2/roles”)



53
54
55
56
57
58
59
60
61
62
# File 'lib/scimitar/rbac/route_helper.rb', line 53

def self.mount_resource_routes(router, resource_name, controller)
  router.instance_exec do
    get    resource_name,            to: "#{controller}#index"
    get    "#{resource_name}/:id",   to: "#{controller}#show"
    post   resource_name,            to: "#{controller}#create"
    put    "#{resource_name}/:id",   to: "#{controller}#replace"
    patch  "#{resource_name}/:id",   to: "#{controller}#update"
    delete "#{resource_name}/:id",   to: "#{controller}#destroy"
  end
end