Class: InstrumentAllTheThings::MethodInstrumentor

Inherits:
Object
  • Object
show all
Defined in:
lib/instrument_all_the_things/method_instrumentor.rb

Constant Summary collapse

WRAPPERS =
{
  # Note that the order of these hash keys are applied top to bottom, with the first inserted key
  # being the inner most wrapper
  gc_stats: Instrumentors::GC_STATS_WRAPPER,
  error_logging: Instrumentors::ERROR_LOGGING_WRAPPER,
  execution_counts_and_timing: Instrumentors::EXECUTION_COUNT_AND_TIMING_WRAPPER,
  trace: Instrumentors::TRACE_WRAPPER,
}.freeze
DEFAULT_OPTIONS =
{
  trace: true,
  gc_stats: false,
  error_logging: true,
  execution_counts_and_timing: false,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ MethodInstrumentor

Returns a new instance of MethodInstrumentor.



25
26
27
28
29
30
31
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 25

def initialize(options)
  self.options = DEFAULT_OPTIONS.merge(options)

  build_instrumentor

  freeze
end

Instance Attribute Details

#instrumentorObject

Returns the value of attribute instrumentor.



23
24
25
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 23

def instrumentor
  @instrumentor
end

#optionsObject

Returns the value of attribute options.



23
24
25
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 23

def options
  @options
end

Instance Method Details

#build_instrumentorObject



33
34
35
36
37
38
39
40
41
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 33

def build_instrumentor
  procs = WRAPPERS.collect do |type, builder|
    next unless options[type]

    builder.call(options[type], options[:context])
  end.compact

  self.instrumentor = combine_procs(procs)
end

#invoke(klass:, &blk) ⇒ Object



43
44
45
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 43

def invoke(klass:, &blk)
  instrumentor.call(klass, blk)
end