Class: RackApiVersioning::Constraint
- Inherits:
-
Object
- Object
- RackApiVersioning::Constraint
- Defined in:
- lib/rack_api_versioning/constraint.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Constraint
constructor
There are four options: :target_version => This is the API version you want to use, when left unspecified it defaults to 1.
-
#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.
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( = {}) @target_version = [:target_version] || 1 @default_version = [:default_version] || 1 @app_name = [:app_name] || "api" @media_type = [: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.
31 32 33 |
# File 'lib/rack_api_versioning/constraint.rb', line 31 def matches?(request) versioned_accept_header?(request) || default_version?(request) end |