Class: Otto::ResponseHandlers::HandlerFactory

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

Overview

Factory for creating response handlers

Constant Summary collapse

HANDLER_MAP =

Map of response type names to handler classes

{
  'json' => JSONHandler,
  'redirect' => RedirectHandler,
  'view' => ViewHandler,
  'auto' => AutoHandler,
  'default' => DefaultHandler
}.freeze

Class Method Summary collapse

Class Method Details

.create_handler(response_type) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/otto/response_handlers.rb', line 124

def self.create_handler(response_type)
  handler_class = HANDLER_MAP[response_type.to_s.downcase]

  unless handler_class
    Otto.logger.warn "Unknown response type: #{response_type}, falling back to default" if Otto.debug
    handler_class = DefaultHandler
  end

  handler_class
end

.handle_response(result, response, response_type, context = {}) ⇒ Object



135
136
137
138
# File 'lib/otto/response_handlers.rb', line 135

def self.handle_response(result, response, response_type, context = {})
  handler = create_handler(response_type)
  handler.handle(result, response, context)
end