Skip to content

Instantly share code, notes, and snippets.

@iamvery
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamvery/10329040 to your computer and use it in GitHub Desktop.
Save iamvery/10329040 to your computer and use it in GitHub Desktop.
# https://github.com/iamvery/rails-api-example/blob/5d304f1983107c4cb609d83a5b6b209ba4064287/app/constraints/api_constraint.rb
class ApiConstraint
attr_reader :version
def initialize(options)
@version = options.fetch(:version)
end
def matches?(request)
request
.headers
.fetch(:accept)
.include?("version=#{version}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment