@@ -6,40 +6,42 @@ module RequestResponse
66 # Specify the default format for the API's serializers.
77 # May be `:json` or `:txt` (default).
88 def default_format ( new_format = nil )
9- namespace_inheritable ( :default_format , new_format &.to_sym )
9+ return inheritable_setting . namespace_inheritable [ :default_format ] if new_format . nil?
10+
11+ inheritable_setting . namespace_inheritable [ :default_format ] = new_format . to_sym
1012 end
1113
1214 # Specify the format for the API's serializers.
1315 # May be `:json`, `:xml`, `:txt`, etc.
1416 def format ( new_format = nil )
15- return namespace_inheritable ( :format ) unless new_format
17+ return inheritable_setting . namespace_inheritable [ :format ] if new_format . nil?
1618
1719 symbolic_new_format = new_format . to_sym
18- namespace_inheritable ( :format , symbolic_new_format )
19- namespace_inheritable ( :default_error_formatter , Grape ::ErrorFormatter . formatter_for ( symbolic_new_format ) )
20+ inheritable_setting . namespace_inheritable [ :format ] = symbolic_new_format
21+ inheritable_setting . namespace_inheritable [ :default_error_formatter ] = Grape ::ErrorFormatter . formatter_for ( symbolic_new_format )
2022
2123 content_type = content_types [ symbolic_new_format ]
2224 raise Grape ::Exceptions ::MissingMimeType . new ( new_format ) unless content_type
2325
24- namespace_stackable ( :content_types , symbolic_new_format => content_type )
26+ inheritable_setting . namespace_stackable [ :content_types ] = { symbolic_new_format => content_type }
2527 end
2628
2729 # Specify a custom formatter for a content-type.
2830 def formatter ( content_type , new_formatter )
29- namespace_stackable ( :formatters , content_type . to_sym => new_formatter )
31+ inheritable_setting . namespace_stackable [ :formatters ] = { content_type . to_sym => new_formatter }
3032 end
3133
3234 # Specify a custom parser for a content-type.
3335 def parser ( content_type , new_parser )
34- namespace_stackable ( :parsers , content_type . to_sym => new_parser )
36+ inheritable_setting . namespace_stackable [ :parsers ] = { content_type . to_sym => new_parser }
3537 end
3638
3739 # Specify a default error formatter.
3840 def default_error_formatter ( new_formatter_name = nil )
39- return namespace_inheritable ( :default_error_formatter ) unless new_formatter_name
41+ return inheritable_setting . namespace_inheritable [ :default_error_formatter ] if new_formatter_name . nil?
4042
4143 new_formatter = Grape ::ErrorFormatter . formatter_for ( new_formatter_name )
42- namespace_inheritable ( :default_error_formatter , new_formatter )
44+ inheritable_setting . namespace_inheritable [ :default_error_formatter ] = new_formatter
4345 end
4446
4547 def error_formatter ( format , options )
@@ -49,13 +51,13 @@ def error_formatter(format, options)
4951 options
5052 end
5153
52- namespace_stackable ( :error_formatters , format . to_sym => formatter )
54+ inheritable_setting . namespace_stackable [ :error_formatters ] = { format . to_sym => formatter }
5355 end
5456
5557 # Specify additional content-types, e.g.:
5658 # content_type :xls, 'application/vnd.ms-excel'
5759 def content_type ( key , val )
58- namespace_stackable ( :content_types , key . to_sym => val )
60+ inheritable_setting . namespace_stackable [ :content_types ] = { key . to_sym => val }
5961 end
6062
6163 # All available content types.
@@ -66,7 +68,9 @@ def content_types
6668
6769 # Specify the default status code for errors.
6870 def default_error_status ( new_status = nil )
69- namespace_inheritable ( :default_error_status , new_status )
71+ return inheritable_setting . namespace_inheritable [ :default_error_status ] if new_status . nil?
72+
73+ inheritable_setting . namespace_inheritable [ :default_error_status ] = new_status
7074 end
7175
7276 # Allows you to rescue certain exceptions that occur to return
@@ -102,12 +106,12 @@ def rescue_from(*args, &block)
102106 handler ||= extract_with ( options )
103107
104108 if args . include? ( :all )
105- namespace_inheritable ( :rescue_all , true )
106- namespace_inheritable ( :all_rescue_handler , handler )
109+ inheritable_setting . namespace_inheritable [ :rescue_all ] = true
110+ inheritable_setting . namespace_inheritable [ :all_rescue_handler ] = handler
107111 elsif args . include? ( :grape_exceptions )
108- namespace_inheritable ( :rescue_all , true )
109- namespace_inheritable ( :rescue_grape_exceptions , true )
110- namespace_inheritable ( :grape_exceptions_rescue_handler , handler )
112+ inheritable_setting . namespace_inheritable [ :rescue_all ] = true
113+ inheritable_setting . namespace_inheritable [ :rescue_grape_exceptions ] = true
114+ inheritable_setting . namespace_inheritable [ :grape_exceptions_rescue_handler ] = handler
111115 else
112116 handler_type =
113117 case options [ :rescue_subclasses ]
@@ -120,7 +124,7 @@ def rescue_from(*args, &block)
120124 inheritable_setting . namespace_reverse_stackable [ handler_type ] = args . to_h { |arg | [ arg , handler ] }
121125 end
122126
123- namespace_stackable ( :rescue_options , options )
127+ inheritable_setting . namespace_stackable [ :rescue_options ] = options
124128 end
125129
126130 # Allows you to specify a default representation entity for a
@@ -146,7 +150,7 @@ def rescue_from(*args, &block)
146150 def represent ( model_class , options )
147151 raise Grape ::Exceptions ::InvalidWithOptionForRepresent . new unless options [ :with ] . is_a? ( Class )
148152
149- namespace_stackable ( :representations , model_class => options [ :with ] )
153+ inheritable_setting . namespace_stackable [ :representations ] = { model_class => options [ :with ] }
150154 end
151155
152156 private
0 commit comments