Class: BloodContracts::Instrumentation::Config

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

Overview

Class that configures the instrumentation for refinement types matching

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Initialize the config with default values Also inits the SessionFinalizer



35
36
37
38
39
40
41
42
# File 'lib/blood_contracts/instrumentation/config.rb', line 35

def initialize
  @instruments = {}
  @finalizer_pool_size = SessionFinalizer::DEFAULT_POOL_SIZE
  @session_finalizer = :basic

  reset_types!
  reset_session_finalizer!
end

Instance Attribute Details

#finalizer_pool_sizeInteger

Pool size of finalizer instance

Returns:

  • (Integer)


25
26
27
# File 'lib/blood_contracts/instrumentation/config.rb', line 25

def finalizer_pool_size
  @finalizer_pool_size
end

#instrumentsHash<Regexp, Array<Instrument>> (readonly)

Map of instrument classes where the key is the matching pattern

Returns:



13
14
15
# File 'lib/blood_contracts/instrumentation/config.rb', line 13

def instruments
  @instruments
end

#session_finalizerSymbol

Type of finalizer instance

Returns:

  • (Symbol)


31
32
33
# File 'lib/blood_contracts/instrumentation/config.rb', line 31

def session_finalizer
  @session_finalizer
end

#typesArray<BC::Refined> (readonly)

List of refinement types defined in the app

Returns:

  • (Array<BC::Refined>)


19
20
21
# File 'lib/blood_contracts/instrumentation/config.rb', line 19

def types
  @types
end

Instance Method Details

#instrument(pattern, processor, **kwargs) ⇒ Nothing

Main setting in the config Define an instument for Refinement Types, applies only to types matched by the pattern by type class name

Parameters:

  • pattern (String, Regexp)

    defines which types to apply this instrument

  • processor (Proc, #call)

    defines the processor for insturmentation session, during the finalize phase the processor#call method would be called with Session instance as a parameter

  • before (Hash)

    a customizable set of options

  • after (Hash)

    a customizable set of options

Returns:

  • (Nothing)


87
88
89
90
91
92
93
94
95
# File 'lib/blood_contracts/instrumentation/config.rb', line 87

def instrument(pattern, processor, **kwargs)
  pattern = /#{pattern}/i unless pattern.is_a?(Regexp)

  old_value = @instruments[pattern].to_a
  new_value = old_value << Instrument.build(processor, **kwargs)
  @instruments[pattern] = new_value

  reset_cache!(pattern)
end