class Speedup::Collectors::Collector
Public Class Methods
key()
click to toggle source
# File lib/speedup/collectors/collector.rb, line 5 def self.key self.name.to_s.split('::').last.gsub(/Collector$/, '').underscore.to_sym end
new(options = {})
click to toggle source
# File lib/speedup/collectors/collector.rb, line 9 def initialize(options = {}) @options = options parse_options setup_subscribes end
Public Instance Methods
context_id()
click to toggle source
Returns String.
# File lib/speedup/collectors/collector.rb, line 46 def context_id "speedup-context-#{key}" end
dom_id()
click to toggle source
The wrapper ID for the individual panel in the Speedup
bar.
Returns String.
# File lib/speedup/collectors/collector.rb, line 53 def dom_id "speedup-panel-#{key}" end
enabled?()
click to toggle source
Conditionally enable views based on any gathered data. Helpful if you don't want views to show up when they return 0 or are touched during the request.
Returns true.
# File lib/speedup/collectors/collector.rb, line 29 def enabled? true end
event_to_data(evt)
click to toggle source
Transfer the event to actual stored data. Default implementation takes full payload, event time and event duration.
# File lib/speedup/collectors/collector.rb, line 82 def event_to_data(evt) evt.payload.merge( time: evt.time, duration: evt.duration ) end
filter_event?(evt)
click to toggle source
# File lib/speedup/collectors/collector.rb, line 86 def filter_event?(evt) !Speedup.enabled? end
key()
click to toggle source
Returns Symbol.
# File lib/speedup/collectors/collector.rb, line 35 def key self.class.key end
Also aliased as: defer_key
parse_options()
click to toggle source
Where any subclasses should pick and pull from @options to set any and all instance variables they like.
Returns nothing.
# File lib/speedup/collectors/collector.rb, line 20 def parse_options # pass end
register(*args, &block)
click to toggle source
# File lib/speedup/collectors/collector.rb, line 61 def register(*args, &block) if block_given? subscribe(*args, &block) else subscribe(*args) do |*args| next unless Speedup.enabled? evt = ActiveSupport::Notifications::Event.new(*args) store_event(evt) unless filter_event?(evt) end end end
render?()
click to toggle source
# File lib/speedup/collectors/collector.rb, line 40 def render? enabled? end
store_event(evt, key=nil)
click to toggle source
Stores en event to request context. Uses a event_to_data
method.
# File lib/speedup/collectors/collector.rb, line 75 def store_event(evt, key=nil) key ||= self.key Speedup.request.store_event(key, event_to_data(evt) ) if Speedup.request end
subscribe(*args, &block)
click to toggle source
# File lib/speedup/collectors/collector.rb, line 57 def subscribe(*args, &block) ActiveSupport::Notifications.subscribe(*args, &block) end
Protected Instance Methods
after_request(&block)
click to toggle source
Helper method for subscribing to the event that is fired when requests are finished.
# File lib/speedup/collectors/collector.rb, line 108 def after_request(&block) subscribe 'process_action.action_controller', &block end
before_request(&block)
click to toggle source
Helper method for subscribing to the event that is fired when new requests are made.
# File lib/speedup/collectors/collector.rb, line 102 def before_request(&block) subscribe 'start_processing.action_controller', &block end
clean_trace()
click to toggle source
# File lib/speedup/collectors/collector.rb, line 92 def clean_trace Rails.backtrace_cleaner.clean(caller[2..-1]) end
setup_subscribes()
click to toggle source
# File lib/speedup/collectors/collector.rb, line 96 def setup_subscribes # pass end