@@ -17,18 +17,16 @@ def default_format(new_format = nil)
1717 # Specify the format for the API's serializers.
1818 # May be `:json`, `:xml`, `:txt`, etc.
1919 def format ( new_format = nil )
20- if new_format
21- namespace_inheritable ( :format , new_format . to_sym )
22- # define the default error formatters
23- namespace_inheritable ( :default_error_formatter , Grape ::ErrorFormatter . formatter_for ( new_format , **{ } ) )
24- # define a single mime type
25- mime_type = content_types [ new_format . to_sym ]
26- raise Grape ::Exceptions ::MissingMimeType . new ( new_format ) unless mime_type
27-
28- namespace_stackable ( :content_types , new_format . to_sym => mime_type )
29- else
30- namespace_inheritable ( :format )
31- end
20+ return namespace_inheritable ( :format ) unless new_format
21+
22+ symbolic_new_format = new_format . to_sym
23+ namespace_inheritable ( :format , symbolic_new_format )
24+ namespace_inheritable ( :default_error_formatter , Grape ::ErrorFormatter . formatter_for ( symbolic_new_format ) )
25+
26+ content_type = content_types [ symbolic_new_format ]
27+ raise Grape ::Exceptions ::MissingMimeType . new ( new_format ) unless content_type
28+
29+ namespace_stackable ( :content_types , symbolic_new_format => content_type )
3230 end
3331
3432 # Specify a custom formatter for a content-type.
@@ -43,12 +41,10 @@ def parser(content_type, new_parser)
4341
4442 # Specify a default error formatter.
4543 def default_error_formatter ( new_formatter_name = nil )
46- if new_formatter_name
47- new_formatter = Grape ::ErrorFormatter . formatter_for ( new_formatter_name , **{ } )
48- namespace_inheritable ( :default_error_formatter , new_formatter )
49- else
50- namespace_inheritable ( :default_error_formatter )
51- end
44+ return namespace_inheritable ( :default_error_formatter ) unless new_formatter_name
45+
46+ new_formatter = Grape ::ErrorFormatter . formatter_for ( new_formatter_name )
47+ namespace_inheritable ( :default_error_formatter , new_formatter )
5248 end
5349
5450 def error_formatter ( format , options )
0 commit comments