@@ -17,18 +17,16 @@ def default_format(new_format = nil)
17
17
# Specify the format for the API's serializers.
18
18
# May be `:json`, `:xml`, `:txt`, etc.
19
19
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 )
32
30
end
33
31
34
32
# Specify a custom formatter for a content-type.
@@ -43,12 +41,10 @@ def parser(content_type, new_parser)
43
41
44
42
# Specify a default error formatter.
45
43
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 )
52
48
end
53
49
54
50
def error_formatter ( format , options )
0 commit comments