Class: InstrumentAllTheThings::MethodInstrumentor

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

Constant Summary collapse

WRAPPERS =
{
  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,
  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.



21
22
23
24
25
26
27
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 21

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

  build_instrumentor

  freeze
end

Instance Attribute Details

#instrumentorObject

Returns the value of attribute instrumentor.



19
20
21
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 19

def instrumentor
  @instrumentor
end

#optionsObject

Returns the value of attribute options.



19
20
21
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 19

def options
  @options
end

Instance Method Details

#build_instrumentorObject



29
30
31
32
33
34
35
36
37
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 29

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



39
40
41
# File 'lib/instrument_all_the_things/method_instrumentor.rb', line 39

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