File: versioner.rb

package info (click to toggle)
ruby-grape 1.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,156 kB
  • sloc: ruby: 25,265; makefile: 7
file content (34 lines) | stat: -rw-r--r-- 922 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

# Versioners set env['api.version'] when a version is defined on an API and
# on the requests. The current methods for determining version are:
#
#   :header - version from HTTP Accept header.
#   :path   - version from uri. e.g. /v1/resource
#   :param  - version from uri query string, e.g. /v1/resource?apiver=v1
#
# See individual classes for details.
module Grape
  module Middleware
    module Versioner
      module_function

      # @param strategy [Symbol] :path, :header or :param
      # @return a middleware class based on strategy
      def using(strategy)
        case strategy
        when :path
          Path
        when :header
          Header
        when :param
          Param
        when :accept_version_header
          AcceptVersionHeader
        else
          raise Grape::Exceptions::InvalidVersionerOption.new(strategy)
        end
      end
    end
  end
end