Class: RailsSpotlight::RenderViewReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_spotlight/render_view_reporter.rb

Class Method Summary collapse

Class Method Details

.dev_instance_variables(source, skip_vars: [], show_devise: false) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/rails_spotlight/render_view_reporter.rb', line 24

def self.dev_instance_variables(source, skip_vars: [], show_devise: false)
  source.instance_variables.map do |name|
    next if skip_vars.include?(name)
    next if RailsSpotlight.config.skip_rendered_ivars.include?(name)
    next if !show_devise && name == :@devise_parameter_sanitizer

    [name[1..], source.instance_variable_get(name)]
  end.compact.to_h
end

.report_rendered_view_locals(view, locals: nil, params: nil, show_devise: false, skip_vars: [], metadata: {}) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/rails_spotlight/render_view_reporter.rb', line 5

def self.report_rendered_view_locals(view, locals: nil, params: nil, show_devise: false, skip_vars: [], metadata: {})
  ActiveSupport::Notifications.instrument(
    'render_view.locals',
    params: params,
    locals: serialize_as_json(locals),
    instance_variables: dev_instance_variables(view, skip_vars: skip_vars, show_devise: show_devise),
    metadata: 
  )
end

.serialize_as_json(value) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rails_spotlight/render_view_reporter.rb', line 15

def self.serialize_as_json(value)
  value.respond_to?(:as_json) ? value.as_json : nil
rescue => e # rubocop:disable Style/RescueStandardError
  {
    __serialization_error: e.message,
    __source: value.inspect
  }
end