File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 1
1
module ActionDispatch
2
2
module Http
3
3
module Parameters
4
+ extend ActiveSupport ::Concern
5
+
4
6
PARAMETERS_KEY = 'action_dispatch.request.path_parameters'
5
7
6
8
DEFAULT_PARSERS = {
@@ -10,13 +12,20 @@ module Parameters
10
12
}
11
13
}
12
14
13
- def self . included ( klass )
14
- class << klass
15
- attr_accessor :parameter_parsers
15
+ included do
16
+ class << self
17
+ attr_reader :parameter_parsers
16
18
end
17
19
18
- klass . parameter_parsers = DEFAULT_PARSERS
20
+ self . parameter_parsers = DEFAULT_PARSERS
19
21
end
22
+
23
+ module ClassMethods
24
+ def parameter_parsers = ( parsers ) # :nodoc:
25
+ @parameter_parsers = parsers . transform_keys { |key | key . respond_to? ( :symbol ) ? key . symbol : key }
26
+ end
27
+ end
28
+
20
29
# Returns both GET and POST \parameters in a single hash.
21
30
def parameters
22
31
params = get_header ( "action_dispatch.request.parameters" )
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ def original_exception
37
37
# The +parsers+ argument can take Hash of parsers where key is identifying
38
38
# content mime type, and value is a lambda that is going to process data.
39
39
def self . new ( app , parsers = { } )
40
+ parsers = parsers . transform_keys { |key | key . respond_to? ( :symbol ) ? key . symbol : key }
40
41
ActionDispatch ::Request . parameter_parsers = ActionDispatch ::Request ::DEFAULT_PARSERS . merge ( parsers )
41
42
app
42
43
end
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ def test_put_json
65
65
66
66
def test_register_and_use_json_simple
67
67
with_test_route_set do
68
- with_params_parsers json : Proc . new { |data | ActiveSupport ::JSON . decode ( data ) [ 'request' ] . with_indifferent_access } do
68
+ with_params_parsers Mime [ :json ] => Proc . new { |data | ActiveSupport ::JSON . decode ( data ) [ 'request' ] . with_indifferent_access } do
69
69
post "/" ,
70
70
params : '{"request":{"summary":"content...","title":"JSON"}}' ,
71
71
headers : { 'CONTENT_TYPE' => 'application/json' }
You can’t perform that action at this time.
0 commit comments