Class: Rack::WebProfiler::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/web_profiler/controller.rb

Overview

Controller

Generate the views of the WebProfiler.

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Controller

Initialize.

Parameters:



13
14
15
# File 'lib/rack/web_profiler/controller.rb', line 13

def initialize(request)
  @request = request
end

Instance Method Details

#deleteRack::Response

Clean the webprofiler.

Returns:

  • (Rack::Response)


72
73
74
75
76
# File 'lib/rack/web_profiler/controller.rb', line 72

def delete
  Rack::WebProfiler::Model.clean!

  redirect WebProfiler::Router.url_for_profiler
end

#indexRack::Response

List the webprofiler history.

Returns:

  • (Rack::Response)


20
21
22
23
24
25
26
27
28
29
# File 'lib/rack/web_profiler/controller.rb', line 20

def index
  @collections = Rack::WebProfiler::Model::CollectionRecord.order(Sequel.desc(:created_at))
    .limit(20)

  return json(@collections, to_json_opts: {
    only: [:token, :http_method, :http_status, :url, :ip]
  }) if prefer_json?

  erb "panel/index.erb", layout: "panel/layout.erb"
end

#show(token) ⇒ Rack::Response

Show the webprofiler panel.

Parameters:

  • token (String)

    The collection token

Returns:

  • (Rack::Response)


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

def show(token)
  @collection = Rack::WebProfiler::Model::CollectionRecord[token: token]
  return not_found if @collection.nil?

  @collectors = Rack::WebProfiler.config.collectors.all
  @collector  = nil

  unless @request.params["panel"].nil?
    @collector = @collectors[@request.params["panel"].to_sym]
  else
    @collector = @collectors.values.first
  end

  return not_found if @collector.nil?

  return json(@collection) if prefer_json?
  erb "panel/show.erb", layout: "panel/layout.erb"
end

#show_toolbar(token) ⇒ Rack::Response

Print the webprofiler toolbar.

Parameters:

  • token (String)

    The collection token

Returns:

  • (Rack::Response)


60
61
62
63
64
65
66
67
# File 'lib/rack/web_profiler/controller.rb', line 60

def show_toolbar(token)
  @collection = Rack::WebProfiler::Model::CollectionRecord[token: token]
  return erb nil, status: 404 if @collection.nil?

  @collectors = Rack::WebProfiler.config.collectors.all

  erb "profiler.erb"
end