class HealthRack::Renderers::HTMLRenderer

Constants

CONTENT_TYPE

Public Class Methods

new(app) click to toggle source
# File lib/health_rack/renderers/html_renderer.rb, line 6
def initialize(app)
  @app = app
end

Public Instance Methods

content_type() click to toggle source
# File lib/health_rack/renderers/html_renderer.rb, line 10
def content_type
  CONTENT_TYPE
end
render(buffer) click to toggle source
# File lib/health_rack/renderers/html_renderer.rb, line 14
      def render(buffer)
        buffer.write <<-HTML
        <doctype html>
        <html>
          <head>
            <meta charset="utf-8">
            <title>#{@app.title}</title>
          </head>
          <body>
            <table border="1">
              <caption>#{@app.title}</caption>
              <thead>
                <tr>
                  <th>&nbsp;</th>
                  <th>Status</th>
                  <th>Time</th>
                </tr>
              </thead>
              <tbody>
        HTML

        results.each do |result|
          buffer.write <<-HTML
          <tr>
            <th>#{result.title}</th>
            <td>#{status(result)}</td>
            <td>#{result.duration.to_f * 1000}</td>
          </tr>
          HTML
        end

        buffer.write <<-HTML
              </tbody>
            </table>
          </body>
        </html>
        HTML
      end

Private Instance Methods

results() click to toggle source
# File lib/health_rack/renderers/html_renderer.rb, line 63
def results
  @results ||= @app.results
end
status(check) click to toggle source
# File lib/health_rack/renderers/html_renderer.rb, line 55
def status(check)
  case
    when check.error? then 'ERROR'
    when check.status? then 'OK'
    else 'FAIL'
  end
end