Class: BloodContracts::Instrumentation::Instrument

Inherits:
Object
  • Object
show all
Defined in:
lib/blood_contracts/instrumentation/instrument.rb

Overview

Base class for instrumentation tooling

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(proto, before: nil, after: nil) ⇒ Instrument, #call

Builds an Instrument class from the proto and before/after callbacks

When ‘proto` is just a Proc - we create new Instrument class around Otherwise - use the `proto` object as an instrument

Also if before/after is defined we add the definition to the ‘proto`

Parameters:

  • proto (#call, Proc)

    callable object that is used as an instrumentation tool

  • before (Hash) (defaults to: nil)

    a customizable set of options

Options Hash (before:):

  • definition (#call, Proc)

    of before callback, it runs right after Session#start in the matching pipeline, the argument is Session instance for current BC::Refined#match call

  • definition (#call, Proc)

    of before callback, it runs right after Session#finish in the matching pipeline, the argument is Session instance for current BC::Refined#match call

Returns:

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/blood_contracts/instrumentation/instrument.rb', line 26

def build(proto, before: nil, after: nil)
  raise ArgumentError unless proto.respond_to?(:call)

  instance = instrument_from_proc(proto)

  if before.respond_to?(:call)
    instance.define_singleton_method(:before, &before)
  end

  define_stub(instance, :before)

  if after.respond_to?(:call)
    instance.define_singleton_method(:after, &after)
  end

  define_stub(instance, :after)

  instance
end

Instance Method Details

#after(_session) ⇒ Nothing

Predefined interface for Instrument after callback, do-no

Parameters:

  • _session (Session)

    to use in callback

Returns:

  • (Nothing)


77
# File 'lib/blood_contracts/instrumentation/instrument.rb', line 77

def after(_session); end

#before(_session) ⇒ Nothing

Predefined interface for Instrument before callback, do-no

Parameters:

  • _session (Session)

    to use in callback

Returns:

  • (Nothing)


69
# File 'lib/blood_contracts/instrumentation/instrument.rb', line 69

def before(_session); end

#call(_session) ⇒ Nothing

Predefined interface for Instrument finalization call, do-no

Parameters:

  • _session (Session)

    to use in callback

Returns:

  • (Nothing)


85
# File 'lib/blood_contracts/instrumentation/instrument.rb', line 85

def call(_session); end