Class: Rack::VersionHeader

Inherits:
Object
  • Object
show all
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

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, options={})
 options[:header_name]  ||= 'X-Version'
 options[:version_file] ||= '.version'

  @app = app
  f = options[:version_file]
  if F.exist?(f.to_s)
    @rev = F.read(f.to_s)
  else
    @rev = 'unknown'
	$stderr.puts("#{F.expand_path(f.to_s)} not found")
  end
  @header_name = options[: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