Module: InstrumentAllTheThings::MethodProxy

Defined in:
lib/instrument_all_the_things/method_proxy.rb

Defined Under Namespace

Modules: Instrumentor

Class Method Summary collapse

Class Method Details

.construct_for_class(klass) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/instrument_all_the_things/method_proxy.rb', line 26

def self.construct_for_class(klass)
  mod = Module.new do
    extend Instrumentor
  end

  mod._iatt_built_for = klass

  mod
end

.find_for_class(klass) ⇒ Object



13
14
15
16
17
18
# File 'lib/instrument_all_the_things/method_proxy.rb', line 13

def self.find_for_class(klass)
  klass.ancestors.detect do |a|
    a.is_a?(Instrumentor) &&
      a._iatt_built_for == klass
  end
end

.for_class(klass) ⇒ Object



9
10
11
# File 'lib/instrument_all_the_things/method_proxy.rb', line 9

def self.for_class(klass)
  find_for_class(klass) || install_on_class(klass)
end

.install_on_class(klass) ⇒ Object



20
21
22
23
24
# File 'lib/instrument_all_the_things/method_proxy.rb', line 20

def self.install_on_class(klass)
  construct_for_class(klass).tap do |m|
    klass.prepend(m)
  end
end