Module: Patternist::Controllers::ActionPack::ResponseHandling

Defined in:
lib/patternist/controllers/actionpack/response_handling.rb

Overview

Handles HTTP and JSON response formatting for controllers. Provides consistent response patterns across controllers with customizable handlers.

Constant Summary collapse

HTML_FORMAT =
:html
JSON_FORMAT =
:json

Instance Method Summary collapse

Instance Method Details

#format_response(resource, notice:, status:, on_error_render:, formats: {}, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/patternist/controllers/actionpack/response_handling.rb', line 12

def format_response(resource, notice:, status:, on_error_render:, formats: {}, &block)
  respond_to do |format|
    if block.call
      handle_success(format, resource, notice, status, formats)
    else
      handle_error(format, resource, on_error_render, formats)
    end
  end
end