lib/grape/middleware/versioner/param.rb in grape-0.13.0 vs lib/grape/middleware/versioner/param.rb in grape-0.14.0

- old
+ new

@@ -19,23 +19,20 @@ # # env['api.version'] => 'v1' class Param < Base def default_options { - parameter: 'apiver' + parameter: 'apiver'.freeze } end def before paramkey = options[:parameter] potential_version = Rack::Utils.parse_nested_query(env[Grape::Http::Headers::QUERY_STRING])[paramkey] - unless potential_version.nil? - if options[:versions] && !options[:versions].find { |v| v.to_s == potential_version } - throw :error, status: 404, message: '404 API Version Not Found', headers: { Grape::Http::Headers::X_CASCADE => 'pass' } - end - env['api.version'] = potential_version - env['rack.request.query_hash'].delete(paramkey) if env.key? 'rack.request.query_hash' - end + return if potential_version.nil? + throw :error, status: 404, message: '404 API Version Not Found', headers: { Grape::Http::Headers::X_CASCADE => 'pass' } if options[:versions] && !options[:versions].find { |v| v.to_s == potential_version } + env[Grape::Env::API_VERSION] = potential_version + env[Grape::Env::RACK_REQUEST_QUERY_HASH].delete(paramkey) if env.key? Grape::Env::RACK_REQUEST_QUERY_HASH end end end end end