1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make ActionDispatch::Request.parameter_parsers public API

It is the proper way to configure custom parameters parser and it was
being recommended in the deprecation for ActionDispatch::ParamsParser.

[ci skip]
This commit is contained in:
Rafael Mendonça França 2017-01-11 00:03:03 -05:00
parent 2e25285213
commit f5ec52d4af
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948

View file

@ -22,6 +22,7 @@ module ActionDispatch
included do
class << self
# Returns the parameter parsers.
attr_reader :parameter_parsers
end
@ -29,7 +30,16 @@ module ActionDispatch
end
module ClassMethods
def parameter_parsers=(parsers) # :nodoc:
# Configure the parameter parser for a give mime type.
#
# It accepts a hash where the key is the symbol of the mime type
# and the value is a proc.
#
# original_parsers = ActionDispatch::Request.parameter_parsers
# xml_parser = -> (raw_post) { Hash.from_xml(raw_post) || {} }
# new_parsers = original_parsers.merge(xml: xml_parser)
# ActionDispatch::Request.parameter_parsers = new_parsers
def parameter_parsers=(parsers)
@parameter_parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key }
end
end