Sha256: 0edf5574dc94f046be91dcced6fcb3a4348839f8922bf911bde4544d06fd061d

Contents?: true

Size: 1.03 KB

Versions: 32

Compression:

Stored size: 1.03 KB

Contents

module Stitches
  # A routing constraint to route versioned requests to the right controller.
  # This allows you to organize your code around version numbers without requiring that clients
  # put version numbers in their URLs.  It's expected that you've set up ValidMimeType
  # as a middleware to ensure these numbers exist
  #
  # Example
  #
  #    namespace :api do
  #      scope module: :v1, constraints: Stitches::ApiVersionConstraint.new(1) do
  #        resource 'ping', only: [ :create ]
  #      end
  #      scope module: :v2, constraints: Stitches::ApiVersionConstraint.new(2) do
  #        resource 'ping', only: [ :create ]
  #      end
  #    end
  #
  # This will route requests with ;version=1 to +Api::V1::PingsController+, while those
  # with ;version=2 will go to +Api::V2::PingsController+.
  #
  class ApiVersionConstraint
    def initialize(version)
      @version = version
    end

    def matches?(request)
      request.headers.fetch(:accept).include?("version=#{@version}")
    rescue KeyError
      false
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
stitches-5.0.0 lib/stitches/api_version_constraint.rb
stitches-5.0.0.RC1 lib/stitches/api_version_constraint.rb
stitches-4.2.2 lib/stitches/api_version_constraint.rb
stitches-4.2.1 lib/stitches/api_version_constraint.rb
stitches-4.2.0 lib/stitches/api_version_constraint.rb
stitches-4.2.0.RC3 lib/stitches/api_version_constraint.rb
stitches-4.2.0.RC2 lib/stitches/api_version_constraint.rb
stitches-4.2.0.RC1 lib/stitches/api_version_constraint.rb
stitches-4.0.2 lib/stitches/api_version_constraint.rb
stitches-4.1.0RC2 lib/stitches/api_version_constraint.rb
stitches-4.0.1 lib/stitches/api_version_constraint.rb
stitches-4.0.0 lib/stitches/api_version_constraint.rb
stitches-4.0.0.RC1 lib/stitches/api_version_constraint.rb
stitches-3.8.3 lib/stitches/api_version_constraint.rb
stitches-3.8.2 lib/stitches/api_version_constraint.rb
stitches-3.8.1 lib/stitches/api_version_constraint.rb
stitches-3.8.0 lib/stitches/api_version_constraint.rb
stitches-3.7.3 lib/stitches/api_version_constraint.rb
stitches-3.7.2 lib/stitches/api_version_constraint.rb
stitches-3.7.0 lib/stitches/api_version_constraint.rb