File tree Expand file tree Collapse file tree 3 files changed +21
-16
lines changed
lib/grape/middleware/versioner Expand file tree Collapse file tree 3 files changed +21
-16
lines changed Original file line number Diff line number Diff line change 55* [ #2629 ] ( https://github.com/ruby-grape/grape/pull/2629 ) : Refactor Router Architecture - [ @ericproulx ] ( https://github.com/ericproulx ) .
66* [ #2633 ] ( https://github.com/ruby-grape/grape/pull/2633 ) : Refactor API::Instance and reorganize DSL modules - [ @ericproulx ] ( https://github.com/ericproulx ) .
77* [ #2636 ] ( https://github.com/ruby-grape/grape/pull/2636 ) : Refactor router to simplify method signatures and reduce duplication - [ @ericproulx ] ( https://github.com/ericproulx ) .
8+ * [ #2640 ] ( https://github.com/ruby-grape/grape/pull/2640 ) : Compute available_media_types once - [ @ericproulx ] ( https://github.com/ericproulx ) .
89* [ #2637 ] ( https://github.com/ruby-grape/grape/pull/2637 ) : Refactor declared method - [ @ericproulx ] ( https://github.com/ericproulx ) .
910* [ #2639 ] ( https://github.com/ruby-grape/grape/pull/2639 ) : Refactor mime_types_for - [ @ericproulx ] ( https://github.com/ericproulx ) .
1011* [ #2638 ] ( https://github.com/ruby-grape/grape/pull/2638 ) : Remove unnecessary path string duplication - [ @ericproulx ] ( https://github.com/ericproulx ) .
Original file line number Diff line number Diff line change @@ -50,6 +50,26 @@ def potential_version_match?(potential_version)
5050 def version_not_found!
5151 throw :error , status : 404 , message : '404 API Version Not Found' , headers : CASCADE_PASS_HEADER
5252 end
53+
54+ private
55+
56+ def available_media_types
57+ @available_media_types ||= begin
58+ media_types = [ ]
59+ base_media_type = "application/vnd.#{ vendor } "
60+ content_types . each_key do |extension |
61+ versions &.reverse_each do |version |
62+ media_types << "#{ base_media_type } -#{ version } +#{ extension } "
63+ media_types << "#{ base_media_type } -#{ version } "
64+ end
65+ media_types << "#{ base_media_type } +#{ extension } "
66+ end
67+
68+ media_types << base_media_type
69+ media_types . concat ( content_types . values . flatten )
70+ media_types
71+ end
72+ end
5373 end
5474 end
5575 end
Original file line number Diff line number Diff line change @@ -105,22 +105,6 @@ def version_not_found!(media_types)
105105
106106 invalid_version_header! ( 'API version not found.' )
107107 end
108-
109- def available_media_types
110- [ ] . tap do |available_media_types |
111- base_media_type = "application/vnd.#{ vendor } "
112- content_types . each_key do |extension |
113- versions &.reverse_each do |version |
114- available_media_types << "#{ base_media_type } -#{ version } +#{ extension } "
115- available_media_types << "#{ base_media_type } -#{ version } "
116- end
117- available_media_types << "#{ base_media_type } +#{ extension } "
118- end
119-
120- available_media_types << base_media_type
121- available_media_types . concat ( content_types . values . flatten )
122- end
123- end
124108 end
125109 end
126110 end
You can’t perform that action at this time.
0 commit comments