Class: Profiler::Collectors::RoutesCollector

Inherits:
BaseCollector show all
Defined in:
lib/profiler/collectors/routes_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
# File 'lib/profiler/collectors/routes_collector.rb', line 27

def collect
  unless defined?(Rails) && Rails.respond_to?(:application) && Rails.application
    return store_data({ routes: [], total: 0 })
  end

  matched_controller, matched_action = recognize_current_route
  routes = build_routes_list(matched_controller, matched_action)
  matched_route = routes.find { |r| r[:matched] }

  store_data({
    total: routes.size,
    matched: matched_route,
    routes: routes
  })
end

#iconObject



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

def icon
  "🗺️"
end

#priorityObject



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

def priority
  12
end

#tab_configObject



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

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

#toolbar_summaryObject



43
44
45
46
47
# File 'lib/profiler/collectors/routes_collector.rb', line 43

def toolbar_summary
  data = panel_content
  matched = data[:matched]
  { text: matched ? matched[:pattern] : "", color: "blue" }
end