Class: RackApiVersioning::Constraint

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_api_versioning/constraint.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Constraint

There are four options: :target_version => This is the API version you want to use, when left unspecified it defaults to 1.

:default_version => This is the API version to failover to, when left unspecified it defaults to 1.

:app_name => The app name that should be included in the 'Accept'

header, when left unspecified it defaults to “api”.

:media_type => The desired media type the API should respond with, when left unspecified it defaults to “*”.



20
21
22
23
24
25
# File 'lib/rack_api_versioning/constraint.rb', line 20

def initialize(options = {})
  @target_version = options[:target_version] || 1
  @default_version = options[:default_version] || 1
  @app_name = options[:app_name] || "api"
  @media_type = options[:media_type] || "*"
end

Instance Method Details

#matches?(request) ⇒ Boolean

Valid versioned API headers look like this: Accept: application/vnd.api-v1+json If no API version header is provided the default API version will be used.

Returns:

  • (Boolean)


31
32
33
# File 'lib/rack_api_versioning/constraint.rb', line 31

def matches?(request)
  versioned_accept_header?(request) || default_version?(request)
end