Class: Callstacking::Rails::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/callstacking/rails/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instrumenter, excluded: []) ⇒ Loader

Returns a new instance of Loader.



8
9
10
11
12
13
14
15
# File 'lib/callstacking/rails/loader.rb', line 8

def initialize(instrumenter, excluded: [])
  @excluded = excluded
  @instrumenter = instrumenter
  @klasses = Set.new
  @settings = Callstacking::Rails::Settings.new

  preloaded_klasses
end

Instance Attribute Details

#excludedObject

Returns the value of attribute excluded.



7
8
9
# File 'lib/callstacking/rails/loader.rb', line 7

def excluded
  @excluded
end

#instrumenterObject

Returns the value of attribute instrumenter.



7
8
9
# File 'lib/callstacking/rails/loader.rb', line 7

def instrumenter
  @instrumenter
end

#klassesObject

Returns the value of attribute klasses.



7
8
9
# File 'lib/callstacking/rails/loader.rb', line 7

def klasses
  @klasses
end

#settingsObject

Returns the value of attribute settings.



7
8
9
# File 'lib/callstacking/rails/loader.rb', line 7

def settings
  @settings
end

Instance Method Details

#on_loadObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/callstacking/rails/loader.rb', line 21

def on_load
  trace = TracePoint.new(:end) do |tp|
    klass = tp.self
    path  = tp.path

    filter_klass(klass, path)
  end

  trace.enable
end

#preloaded_klassesObject



17
18
19
# File 'lib/callstacking/rails/loader.rb', line 17

def preloaded_klasses
  ObjectSpace.each_object(Module){|ob| filter_klass(ob, (Object.const_source_location(ob.to_s)&.first rescue nil))}
end

#reset!Object



32
33
34
35
# File 'lib/callstacking/rails/loader.rb', line 32

def reset!
  instrumenter.instrument_method(ActionView::PartialRenderer, :render, application_level: false)
  instrumenter.instrument_method(ActionView::TemplateRenderer, :render, application_level: false)
end