Class: Profiler::Collectors::RequestCollector

Inherits:
BaseCollector show all
Defined in:
lib/profiler/collectors/request_collector.rb

Instance Attribute Summary

Attributes inherited from BaseCollector

#profile

Instance Method Summary collapse

Methods inherited from BaseCollector

descendants, #has_data?, inherited, #initialize, #name, #panel_content, #render_html, #render_mode, #subscribe

Constructor Details

This class inherits a constructor from Profiler::Collectors::BaseCollector

Instance Method Details

#collectObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/profiler/collectors/request_collector.rb', line 27

def collect
  data = {
    path: @profile.path,
    method: @profile.method,
    status: @profile.status,
    duration: @profile.duration,
    memory: @profile.memory,
    params: @profile.params,
    headers: @profile.headers,
    response_headers: @profile.response_headers,
    request_body: @profile.request_body,
    request_body_encoding: @profile.request_body_encoding,
    response_body: @profile.response_body,
    response_body_encoding: @profile.response_body_encoding,
    started_at: @profile.started_at&.iso8601,
    finished_at: @profile.finished_at&.iso8601
  }

  data.merge!(collect_route_info)
  store_data(data)
end

#iconObject



8
9
10
# File 'lib/profiler/collectors/request_collector.rb', line 8

def icon
  "🌐"
end

#priorityObject



12
13
14
# File 'lib/profiler/collectors/request_collector.rb', line 12

def priority
  10
end

#tab_configObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/profiler/collectors/request_collector.rb', line 16

def tab_config
  {
    key: "request",
    label: "Request",
    icon: icon,
    priority: priority,
    enabled: true,
    default_active: false
  }
end

#toolbar_summaryObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/profiler/collectors/request_collector.rb', line 49

def toolbar_summary
  status_color = case @profile.status
                when 200..299 then "green"
                when 300..399 then "blue"
                when 400..499 then "orange"
                when 500..599 then "red"
                else "gray"
                end

  {
    text: "#{@profile.method} #{@profile.status}",
    color: status_color,
    duration: @profile.duration,
    memory: format_memory(@profile.memory)
  }
end