Class: Hud::Middleware::Environment

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Environment

Returns a new instance of Environment.



55
56
57
# File 'lib/hud.rb', line 55

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hud.rb', line 59

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


  if ENV['HUD_SHOW_ENVIROMENT']
    color = 'green'
    color = 'orange' if ENV['HUD_ENV'] == "next" 
    color = 'red' if ENV['HUD_ENV'] == "live" 

    response_body = ''
    response.each { |part| response_body << part }
    indicator_div = "<div style='position:fixed; top:0; z-index:9999; height:30px; width:100%; background-color:#{color}; z-index:9999;'>#{ENV['HARBR_ENV']&.upcase} ENVIRONMENT</div>"
    response_body.sub!("<body>", "<body>#{indicator_div}")
    headers["Content-Length"] = response_body.bytesize.to_s
  end

  response = [response_body]


  [status, headers, response]
end