Class: Grape::Middleware::Versioner
- Defined in:
- lib/grape/middleware/versioner.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#after, #call, #call!, #initialize, #request, #response
Constructor Details
This class inherits a constructor from Grape::Middleware::Base
Instance Method Details
#before ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/grape/middleware/versioner.rb', line 12 def before pieces = env['PATH_INFO'].split('/') potential_version = pieces[1] if potential_version =~ [:pattern] if [:versions] && ![:versions].include?(potential_version) throw :error, :status => 404, :message => "404 API Version Not Found" end truncated_path = "/#{pieces[2..-1].join('/')}" env['api.version'] = potential_version env['PATH_INFO'] = truncated_path end end |
#default_options ⇒ Object
6 7 8 9 10 |
# File 'lib/grape/middleware/versioner.rb', line 6 def { :pattern => /.*/i } end |