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

Constant Summary collapse

KNOWN_KEYS =

Mount CRUD routes for all RBAC resources.

%i[roles_controller entitlements_controller applications_controller].freeze

Class Method Summary collapse

Class Method Details

.mount_rbac_routes(router, **options) ⇒ Object



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

def self.mount_rbac_routes(router, **options)
  unknown = options.keys - KNOWN_KEYS
  if unknown.any?
    raise ArgumentError, "mount_rbac_routes: unknown option(s): #{unknown.map(&:inspect).join(', ')}. " \
                         "Valid keys: #{KNOWN_KEYS.map(&:inspect).join(', ')}"
  end

  mount_resource_routes(router, "Roles",         options[:roles_controller])         if options[:roles_controller]
  mount_resource_routes(router, "Entitlements",  options[:entitlements_controller])  if options[:entitlements_controller]
  mount_resource_routes(router, "Applications",  options[:applications_controller])  if options[:applications_controller]
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