Skip to content

Commit dc48d6d

Browse files
shunwenlgebhardt
authored andcommitted
Refactor ensure_valid_accept_media_type
1 parent ec3df22 commit dc48d6d

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

lib/jsonapi/acts_as_resource_controller.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,20 @@ def ensure_correct_media_type
126126
end
127127

128128
def ensure_valid_accept_media_type
129-
if invalid_accept_media_type?
129+
unless valid_accept_media_type?
130130
fail JSONAPI::Exceptions::NotAcceptableError.new(request.accept)
131131
end
132132
rescue => e
133133
handle_exceptions(e)
134134
end
135135

136-
def invalid_accept_media_type?
136+
def valid_accept_media_type?
137137
media_types = media_types_for('Accept')
138138

139-
return false if media_types.blank? || media_types.include?(ALL_MEDIA_TYPES)
140-
141-
jsonapi_media_types = media_types.select do |media_type|
142-
media_type.include?(JSONAPI::MEDIA_TYPE)
143-
end
144-
145-
jsonapi_media_types.size.zero? ||
146-
jsonapi_media_types.none? do |media_type|
147-
media_type == JSONAPI::MEDIA_TYPE
148-
end
139+
media_types.blank? ||
140+
media_types.any? do |media_type|
141+
(media_type == JSONAPI::MEDIA_TYPE || media_type == ALL_MEDIA_TYPES)
142+
end
149143
end
150144

151145
def media_types_for(header)

0 commit comments

Comments
 (0)