Skip to content

Instantly share code, notes, and snippets.

@austenito
Created May 31, 2013 01:28
Show Gist options
  • Save austenito/5682453 to your computer and use it in GitHub Desktop.
Save austenito/5682453 to your computer and use it in GitHub Desktop.
module Router
class ApiConstraints
def initialize(options)
@version = options[:version]
@default = options[:default]
end
def default?
@default
end
def matches?(request)
default? || request.headers['Accept'].include?("application/vnd.customer_profile_service.v#{@version}")
end
end
end
namespace :api, defaults: {format: 'json'} do
scope module: :v1, constraints: Router::ApiConstraints.new(version: 1, default: true) do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment