Skip to content

Instantly share code, notes, and snippets.

@sosedoff
Created December 12, 2011 23:08
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 sosedoff/1469571 to your computer and use it in GitHub Desktop.
Save sosedoff/1469571 to your computer and use it in GitHub Desktop.
Add X-Revision headers from capistrano deployment
module Rack
class Revision
@@revision = nil
File = ::File
def initialize(app, &block)
@app = app
@block = block
@file = File.join(Dir.pwd, 'REVISION')
end
def call(env)
status, headers, body = @app.call(env)
headers['X-Revision'] = revision
[status, headers, body]
end
protected
def revision
@@revision ||= read_revision
end
def read_revision
File.exists?(@file) ? File.read(@file).strip : 'UNDEFINED'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment