Class: Otto::RouteHandlers::HandlerFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/otto/route_handlers/factory.rb

Overview

Factory for creating appropriate handlers based on route definitions

Class Method Summary collapse

Class Method Details

.create_handler(route_definition, otto_instance = nil) ⇒ BaseHandler

Create a handler for the given route definition

Parameters:

  • route_definition (Otto::RouteDefinition)

    The route definition

  • otto_instance (Otto) (defaults to: nil)

    The Otto instance for configuration access

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/otto/route_handlers/factory.rb', line 16

def self.create_handler(route_definition, otto_instance = nil)
  # Create base handler based on route kind
  handler_class = case route_definition.kind
                  when :logic then LogicClassHandler
                  when :instance then InstanceMethodHandler
                  when :class then ClassMethodHandler
                  else
                    raise ArgumentError, "Unknown handler kind: #{route_definition.kind}"
                  end

  handler = handler_class.new(route_definition, otto_instance)

  # Always wrap with RouteAuthWrapper to ensure env['otto.strategy_result'] is set
  # - Routes WITH auth requirement: Enforces authentication
  # - Routes WITHOUT auth requirement: Sets anonymous StrategyResult
  if otto_instance&.auth_config
    handler = Otto::Security::Authentication::RouteAuthWrapper.new(
      handler,
      route_definition,
      otto_instance.auth_config,
      otto_instance.security_config
    )
  end

  handler
end