-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
418 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
VersionCake.setup do |config| | ||
# Set the version key that clients will send example: `X-API-VERSION: 5` | ||
# config.version_key = 'version' | ||
|
||
# Enable Rails versioned filename mapping | ||
# config.rails_view_versioning = true | ||
|
||
# Extraction Strategies | ||
# Define how you will accept version from the request. | ||
# | ||
# Defaults to all: | ||
# [:http_accept_parameter, :http_header, :request_parameter, :path_parameter, :query_parameter] | ||
# | ||
# Custom strategy example: | ||
# You can create your own extraction strategy by giving a proc or class that responds to execute: | ||
# ``` | ||
# lambda {|request| request.headers["HTTP_X_MY_VERSION"] } | ||
# ``` | ||
# or | ||
# ``` | ||
# class ExtractorStrategy | ||
# def execute(request) | ||
# request.headers["HTTP_X_MY_VERSION"] | ||
# end | ||
# end | ||
# ``` | ||
# config.extraction_strategy = [:http_accept_parameter, :http_header, :request_parameter, :path_parameter, :query_parameter] | ||
|
||
# Version when no version in present in the request. If none is | ||
# specified then it will error? | ||
# config.missing_version = 5 | ||
|
||
# Versioned Resources | ||
# Define what server resources are supported, deprecated or obsolete | ||
# Resources listed are priority based upon creation. To version all | ||
# resources you can define a catch all at the bottom of the block. | ||
config.resources do |r| | ||
# r.resource uri_regex, obsolete, deprecated, supported | ||
r.resource %r{.*}, [], [], (1..5) | ||
end | ||
end | ||
|
||
# TODO: Remove! | ||
|
||
# Versioned resources are described by a URI pattern | ||
# versioned_resources = { | ||
# * => { | ||
# supported: (1..LATEST) | ||
# } | ||
# %r{users} => { | ||
# obsolute: 2, | ||
# deprecated: 3, | ||
# supported: 4, | ||
# rewrite_uri: 'user' | ||
# }, | ||
# %r{user} => { | ||
# supported: (5..LATEST) | ||
# } | ||
# } | ||
# | ||
# v1/users => 404 | ||
# v2/users => 410 (GONE) | ||
# v3/users => 'v3/user' with warning | ||
# v4/users => 'v4/user' | ||
# v5/users => 404 | ||
# v5/user => 'v5/user' | ||
# v6/user => 'v6/user' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'rails/generators' | ||
|
||
module Versioncake | ||
class InstallGenerator < Rails::Generators::Base | ||
source_root File.expand_path('../../templates', __FILE__) | ||
|
||
desc 'Creates a Version Cake initializer in your application.' | ||
def copy_initializer | ||
template 'versioncake.rb', 'config/initializers/versioncake.rb' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module VersionCake | ||
class Engine < Rails::Engine | ||
initializer 'version_cake.add_middleware' do |app| | ||
app.middleware.use VersionCake::Rack::Middleware | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module VersionCake | ||
module Rack | ||
class Middleware | ||
|
||
def initialize(app) | ||
@app = app | ||
@versioned_resources = VersionCake.config.versioned_resources | ||
@default_version = VersionCake.config.missing_version | ||
@strategies = VersionCake.config.extraction_strategies | ||
end | ||
|
||
def call(env) | ||
raw_request = ::Rack::Request.new env | ||
resource = @versioned_resources.find { |resource| resource.uri.match raw_request.path } | ||
|
||
if resource | ||
request = VersionCake::VersionedRequest.new(raw_request, @strategies, @default_version) | ||
request.execute | ||
checker = VersionCake::VersionChecker.new(resource, request) | ||
checker.execute | ||
|
||
env['versioncake.context'] = VersionCake::VersionContext.new(request.version, resource, checker.result) | ||
end | ||
|
||
@app.call(env) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module VersionCake | ||
module TestHelpers | ||
def set_request_version(version_number, version_status=:supported, supported_versions=[version_number]) | ||
if version_number.is_a? Symbol | ||
version_status = version_number | ||
if version_status == :supported | ||
version_number = 1 | ||
else | ||
version_number = 666 | ||
end | ||
end | ||
|
||
@request.env['versioncake.context'] = VersionCake::VersionContext.new( | ||
version_number, | ||
instance_double('VersionedResource', latest_version: supported_versions.last, supported_versions: supported_versions), | ||
version_status | ||
) | ||
end | ||
end | ||
end |
Oops, something went wrong.