Class: Rack::Insight::Toolbar

Inherits:
Toolbar
  • Object
show all
Includes:
Logging, PathMatchFilters, Render
Defined in:
lib/rack/insight/toolbar.rb

Instance Method Summary collapse

Methods included from PathMatchFilters

#match_path_filters?, #to_regex

Methods included from Logging

logger, verbose, verbosity

Methods included from Render

#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params

Constructor Details

#initialize(app, insight, options = {}) ⇒ Toolbar

Returns a new instance of Toolbar.



7
8
9
10
11
# File 'lib/rack/insight/toolbar.rb', line 7

def initialize(app, insight, options = {})
  super app, options
  @insight = insight
  @request_table = Database::RequestTable.new
end

Instance Method Details

#current_request_fragmentObject



41
42
43
44
45
46
# File 'lib/rack/insight/toolbar.rb', line 41

def current_request_fragment
  render_template("request_fragment",
                  :request_id => req_id,
                  :panels => @insight.panels,
                  :requests => requests)
end

#ensure_no_cacheObject

Ensure that browser doesn’t cache



19
20
21
22
# File 'lib/rack/insight/toolbar.rb', line 19

def ensure_no_cache
  @headers["Etag"] = ""
  @headers["Cache-Control"] = "no-cache"
end

#headers_fragmentObject



34
35
36
37
38
39
# File 'lib/rack/insight/toolbar.rb', line 34

def headers_fragment
  render_template("headers_fragment",
                  :request_id => req_id,
                  :panels => @insight.panels,
                  :handle_javascript => @insight.config[:handle_javascript])
end

#okay_to_modify?Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/rack/insight/toolbar.rb', line 13

def okay_to_modify?
  super
  return !match_path_filters?(@env["rack-insight.path_filters"], @env["REQUEST_PATH"])
end

#renderObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rack/insight/toolbar.rb', line 48

def render
  ensure_no_cache

  unless verbose(:silent)
    logger.info do
      "Injecting toolbar: active panels: #{@insight.panels.map{|pnl| pnl.class.name}.inspect}"
    end
  end

  html = render_template("toolbar",
                         :request_id => req_id,
                         :request_fragment => current_request_fragment,
                         :headers_fragment => headers_fragment,
                         :handle_javascript => Rack::Insight::Config.config[:handle_javascript])
  html.force_encoding('UTF-8') if RUBY_VERSION > '1.9.0'
  html
end

#req_idObject



24
25
26
# File 'lib/rack/insight/toolbar.rb', line 24

def req_id
  @req_id ||= (@env['rack-insight.request-id'] || @request_table.last_request_id).to_i
end

#requestsObject



28
29
30
31
32
# File 'lib/rack/insight/toolbar.rb', line 28

def requests
  @requests ||= @request_table.to_a.map do |row|
    { :id => row[0], :method => row[1], :path => row[2] }
  end
end