lib/grape/dsl/inside_route.rb in grape-0.19.0 vs lib/grape/dsl/inside_route.rb in grape-0.19.1

- old
+ new

@@ -120,24 +120,28 @@ def status(status = nil) case status when Symbol raise ArgumentError, "Status code :#{status} is invalid." unless Rack::Utils::SYMBOL_TO_STATUS_CODE.keys.include?(status) @status = Rack::Utils.status_code(status) - when Fixnum + when Integer @status = status when nil return @status if @status case request.request_method.to_s.upcase when Grape::Http::Headers::POST 201 when Grape::Http::Headers::DELETE - 204 + if @body.present? + 200 + else + 204 + end else 200 end else - raise ArgumentError, 'Status code must be Fixnum or Symbol.' + raise ArgumentError, 'Status code must be Integer or Symbol.' end end # Set response content-type def content_type(val = nil) @@ -177,9 +181,23 @@ @body = '' status 204 else @body end + end + + # Allows you to explicitly return no content. + # + # @example + # delete :id do + # return_no_content + # "not returned" + # end + # + # DELETE /12 # => 204 No Content, "" + def return_no_content + status 204 + body false end # Allows you to define the response as a file-like object. # # @example