Merge pull request #50063 from skipkayhil/hm-doc-metal

Add documentation for delegated methods on Metal
This commit is contained in:
Hartley McGuire 2024-07-11 01:58:43 +00:00 committed by GitHub
commit 8950070e55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 8 deletions

@ -81,14 +81,14 @@ def build_middleware(klass, args, block)
# #
# get 'hello', to: HelloController.action(:index) # get 'hello', to: HelloController.action(:index)
# #
# The `action` method returns a valid Rack application for the Rails router to # The ::action method returns a valid Rack application for the Rails router to
# dispatch to. # dispatch to.
# #
# ## Rendering Helpers # ## Rendering Helpers
# #
# `ActionController::Metal` by default provides no utilities for rendering # By default, `ActionController::Metal` provides no utilities for rendering
# views, partials, or other responses aside from explicitly calling of # views, partials, or other responses aside from some low-level setters such
# `response_body=`, `content_type=`, and `status=`. To add the render helpers # as #response_body=, #content_type=, and #status=. To add the render helpers
# you're used to having in a normal controller, you can do the following: # you're used to having in a normal controller, you can do the following:
# #
# class HelloController < ActionController::Metal # class HelloController < ActionController::Metal
@ -179,8 +179,33 @@ def controller_name
# Delegates to ActionDispatch::Response#headers. # Delegates to ActionDispatch::Response#headers.
delegate :headers, to: "@_response" delegate :headers, to: "@_response"
delegate :status=, :location=, :content_type=, ##
:status, :location, :content_type, :media_type, to: "@_response" # Delegates to ActionDispatch::Response#status=
delegate :status=, to: "@_response"
##
# Delegates to ActionDispatch::Response#location=
delegate :location=, to: "@_response"
##
# Delegates to ActionDispatch::Response#content_type=
delegate :content_type=, to: "@_response"
##
# Delegates to ActionDispatch::Response#status
delegate :status, to: "@_response"
##
# Delegates to ActionDispatch::Response#location
delegate :location, to: "@_response"
##
# Delegates to ActionDispatch::Response#content_type
delegate :content_type, to: "@_response"
##
# Delegates to ActionDispatch::Response#media_type
delegate :media_type, to: "@_response"
def initialize def initialize
@_request = nil @_request = nil
@ -201,7 +226,7 @@ def params=(val)
alias :response_code :status # :nodoc: alias :response_code :status # :nodoc:
# Basic url_for that can be overridden for more robust functionality. # Basic `url_for` that can be overridden for more robust functionality.
def url_for(string) def url_for(string)
string string
end end

@ -231,6 +231,18 @@ def sending?; synchronize { @sending }; end
def committed?; synchronize { @committed }; end def committed?; synchronize { @committed }; end
def sent?; synchronize { @sent }; end def sent?; synchronize { @sent }; end
##
# :method: location
#
# Location of the response.
##
# :method: location=
#
# :call-seq: location=(location)
#
# Sets the location of the response
# Sets the HTTP status code. # Sets the HTTP status code.
def status=(status) def status=(status)
@status = Rack::Utils.status_code(status) @status = Rack::Utils.status_code(status)
@ -241,7 +253,7 @@ def status=(status)
# #
# response.content_type = "text/plain" # response.content_type = "text/plain"
# #
# If a character set has been defined for this response (see charset=) then the # If a character set has been defined for this response (see #charset=) then the
# character set information will also be included in the content type # character set information will also be included in the content type
# information. # information.
def content_type=(content_type) def content_type=(content_type)