Class: Otto::RouteHandlers::HandlerFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/otto/route_handlers.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:



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/otto/route_handlers.rb', line 14

def self.create_handler(route_definition, otto_instance = nil)
  case route_definition.kind
  when :logic
    LogicClassHandler.new(route_definition, otto_instance)
  when :instance
    InstanceMethodHandler.new(route_definition, otto_instance)
  when :class
    ClassMethodHandler.new(route_definition, otto_instance)
  else
    raise ArgumentError, "Unknown handler kind: #{route_definition.kind}"
  end
end