Created
December 12, 2011 23:08
-
-
Save sosedoff/1469571 to your computer and use it in GitHub Desktop.
Add X-Revision headers from capistrano deployment
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
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