Class: Hud::Middleware::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/hud.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Version

Returns a new instance of Version.



31
32
33
34
35
# File 'lib/hud.rb', line 31

def initialize(app)
  @app = app
  manifest_path = File.join('config', 'manifest.yml')
  @version = YAML.load_file(manifest_path)['version']
end

Instance Method Details

#call(env) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hud.rb', line 37

def call(env)
  status, headers, response = @app.call(env)


  if ENV['HUD_SHOW_VERSION']
    response_body = ''
    response.each { |part| response_body << part }
    version_div = "<div style='position:fixed; bottom:0; right:0; z-index:9999; background-color:rgba(255, 255, 255, 0.7); padding:5px;'>Version: #{@version}</div>"
    response_body.sub!("</body>", "#{version_div}</body>")
    headers["Content-Length"] = response_body.bytesize.to_s

    response = [response_body]
  end

  [status, headers, response]
end