Sha256: e329e2930ba864af2b3582e325fea7a3fa67dd4cd0665bc0c0a8debeb219be7e

Contents?: true

Size: 523 Bytes

Versions: 2

Compression:

Stored size: 523 Bytes

Contents

require 'grape/middleware/base'

module Grape
  module Middleware
    class Versioner < Base
      def default_options
        {
          :pattern => /.*/i
        }
      end
      
      def before
        pieces = env['PATH_INFO'].split('/')
        potential_version = pieces[1]
        if potential_version =~ options[:pattern]
          truncated_path = "/#{pieces[2..-1].join('/')}"
          env['api.version'] = potential_version
          env['PATH_INFO'] = truncated_path
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-0.0.0.alpha.2 lib/grape/middleware/versioner.rb
grape-0.0.0.alpha.1 lib/grape/middleware/versioner.rb