Class: Profiler::Collectors::BaseCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/profiler/collectors/base_collector.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile) ⇒ BaseCollector

Returns a new instance of BaseCollector.



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

def initialize(profile)
  @profile = profile
  @data = {}
end

Instance Attribute Details

#profileObject (readonly)

Returns the value of attribute profile.



6
7
8
# File 'lib/profiler/collectors/base_collector.rb', line 6

def profile
  @profile
end

Class Method Details

.descendantsObject



80
81
82
# File 'lib/profiler/collectors/base_collector.rb', line 80

def self.descendants
  @descendants || []
end

.inherited(subclass) ⇒ Object



74
75
76
77
78
# File 'lib/profiler/collectors/base_collector.rb', line 74

def self.inherited(subclass)
  super
  # Auto-register collectors
  (@descendants ||= []) << subclass
end

Instance Method Details

#collectObject



60
61
62
# File 'lib/profiler/collectors/base_collector.rb', line 60

def collect
  # Override in subclasses to collect data
end

#has_data?Boolean

Whether this collector has data for the current profile

Returns:

  • (Boolean)


48
49
50
51
52
53
54
# File 'lib/profiler/collectors/base_collector.rb', line 48

def has_data?
  data = panel_content
  return false if data.nil?
  return false if data.is_a?(Hash) && data.empty?
  return false if data.is_a?(Array) && data.empty?
  true
end

#iconObject



17
18
19
# File 'lib/profiler/collectors/base_collector.rb', line 17

def icon
  "📊"
end

#nameObject



13
14
15
# File 'lib/profiler/collectors/base_collector.rb', line 13

def name
  self.class.name.split("::").last.gsub("Collector", "").downcase
end

#panel_contentObject



69
70
71
72
# File 'lib/profiler/collectors/base_collector.rb', line 69

def panel_content
  # Override in subclasses to provide full panel content
  @data
end

#priorityObject



21
22
23
# File 'lib/profiler/collectors/base_collector.rb', line 21

def priority
  100
end

#render_html(profile) ⇒ Object

For custom HTML rendering from backend (when render_mode is :custom)



43
44
45
# File 'lib/profiler/collectors/base_collector.rb', line 43

def render_html(profile)
  nil
end

#render_modeObject

How to render the tab: :auto (use JSON), :custom (call render_html), :client (frontend renderer)



38
39
40
# File 'lib/profiler/collectors/base_collector.rb', line 38

def render_mode
  :auto
end

#subscribeObject



56
57
58
# File 'lib/profiler/collectors/base_collector.rb', line 56

def subscribe
  # Override in subclasses to subscribe to ActiveSupport::Notifications
end

#tab_configObject

Tab configuration for dynamic tab system



26
27
28
29
30
31
32
33
34
35
# File 'lib/profiler/collectors/base_collector.rb', line 26

def tab_config
  {
    key: name,
    label: name.capitalize,
    icon: icon,
    priority: priority,
    enabled: true,
    default_active: false
  }
end

#toolbar_summaryObject



64
65
66
67
# File 'lib/profiler/collectors/base_collector.rb', line 64

def toolbar_summary
  # Override in subclasses to provide summary for toolbar
  ""
end