Created
October 10, 2012 16:15
-
-
Save acidlabs-snippets/3866640 to your computer and use it in GitHub Desktop.
Git Revision Middleware
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
# lib/rack/revision.rb | |
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 | |
# config.ru | |
use Rack::Revision |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment