Module: Runger::Tracing

Included in:
Env, Loaders::Base
Defined in:
lib/runger/tracing.rb,
lib/runger_config.rb

Overview

Provides method to trace values association

Defined Under Namespace

Classes: Trace

Class Method Summary collapse

Class Method Details

.captureObject



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/runger/tracing.rb', line 138

def capture
  unless ::Runger::Settings.tracing_enabled
    yield
    return
  end

  trace = Trace.new
  trace_stack.push(trace)
  yield
  trace_stack.last
ensure
  trace_stack.pop
end

.current_traceObject Also known as: tracing?



156
# File 'lib/runger/tracing.rb', line 156

def current_trace = trace_stack.last

.current_trace_sourceObject



164
165
166
# File 'lib/runger/tracing.rb', line 164

def current_trace_source
  source_stack.last || accessor_source(caller_locations(2, 1).first)
end

.source_stackObject



160
161
162
# File 'lib/runger/tracing.rb', line 160

def source_stack
  (Thread.current[:__runger__trace_source_stack__] ||= [])
end

.trace!(type, *path, **options) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/runger/tracing.rb', line 184

def trace!(type, *path, **options)
  return yield unless ::Runger::Tracing.tracing?

  val = yield
  if val.is_a?(Hash)
    ::Runger::Tracing.current_trace.merge_values(val, type:, **options)
  elsif !path.empty?
    ::Runger::Tracing.current_trace.record_value(val, *path, type:, **options)
  end
  val
end

.trace_stackObject



152
153
154
# File 'lib/runger/tracing.rb', line 152

def trace_stack
  (Thread.current[:__runger__trace_stack__] ||= [])
end

.with_trace_source(src) ⇒ Object



168
169
170
171
172
173
# File 'lib/runger/tracing.rb', line 168

def with_trace_source(src)
  source_stack << src
  yield
ensure
  source_stack.pop
end