Module: Sqreen::EcosystemIntegration::InstrumentationService

Defined in:
lib/sqreen/ecosystem_integration/instrumentation_service.rb

Class Method Summary collapse

Class Method Details

.instrument(module_name, method, spec) ⇒ Object

Parameters:

  • module_name (String)
  • method (String)

    in form A::B#c or A::B.c

  • spec (Hash{Symbol=>Proc})


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sqreen/ecosystem_integration/instrumentation_service.rb', line 16

def instrument(module_name, method, spec)
  hook = Sqreen::Graft::Hook[method].add do
    if spec[:before]
      cb = AroundCallbacks.wrap_instrumentation_hook(module_name, 'pre', spec[:before])
      before(nil, flow: true, &cb)
    end

    if spec[:after]
      cb = AroundCallbacks.wrap_instrumentation_hook(module_name, 'post', spec[:after])
      after(nil, flow: true, &cb)
    end

    if spec[:raised]
      cb = AroundCallbacks.wrap_instrumentation_hook(module_name, 'failing', spec[:raised])
      raised(nil, flow: true, &cb)
    end

    if spec[:ensured]
      cb = AroundCallbacks.wrap_instrumentation_hook(module_name, 'finally', spec[:ensured])
      ensured(nil, flow: true, &cb)
    end
  end
  hook.install
end