module Syro::Versioning

Include on `Syro::Deck` to enable API versioning

Constants

VERSION

Public Instance Methods

request_version() click to toggle source

Fetch the version for the current request's Accept header

@returns [Integer] The matched version number

# File lib/syro/versioning.rb, line 39
def request_version
  @request_version ||= if match = /version=(\d+)/.match(req.env['HTTP_ACCEPT'])
    match[1].to_i
  else
    now = Time.now
    now.day + 100*now.month + 10000*now.year
  end
end
version(number,&block) click to toggle source

Describe a version block inside a Syro app.

@param number [Integer] The minimum version number to match. @param block The route to process if version matches. @returns [void]

@example

Syro.new(AppDeck) {
  version(20150101) {
    get {
      res.write "Version 2015-01-01"
    }
  }
  version(1) {
    get {
      res.write "Version 1"
    }
  }
}
# File lib/syro/versioning.rb, line 30
def version(number,&block)
  return if number > request_version
  instance_eval(&block)
end