Class: Rack::VersionHeader
- Inherits:
-
Object
- Object
- Rack::VersionHeader
- Defined in:
- lib/rack/version_header.rb
Overview
Rack Version Header A Rack middleware for adding a version response header git show-ref –verify refs/heads/master –hash=8
Constant Summary collapse
- F =
::File
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ VersionHeader
constructor
A new instance of VersionHeader.
Constructor Details
#initialize(app, options = {}) ⇒ VersionHeader
Returns a new instance of VersionHeader.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rack/version_header.rb', line 9 def initialize(app, ={}) [:header_name] ||= 'X-Version' [:version_file] ||= '.version' @app = app f = [:version_file] if F.exist?(f.to_s) @rev = F.read(f.to_s) else @rev = 'unknown' $stderr.puts("#{F.(f.to_s)} not found") end @header_name = [:header_name] end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 |
# File 'lib/rack/version_header.rb', line 24 def call(env) status, headers, response = @app.call(env) headers[@header_name] = @rev [status, headers, response] end |