Module: Trailblazer::Developer::Wtf
- Defined in:
- lib/trailblazer/developer/wtf.rb,
lib/trailblazer/developer/wtf/renderer.rb
Defined Under Namespace
Modules: Renderer
Class Method Summary collapse
- .arguments_for_trace(activity, ctx, original_flow_options, **circuit_options) ⇒ Object
-
.capture_variables?(step_name:, focus_on:) ⇒ Boolean
private.
-
.invoke(activity, ctx, flow_options, **circuit_options) ⇒ Object
Run activity with tracing enabled and inject a mutable Stack instance.
-
.trace_input_data_collector(wrap_config, ctx, flow_options, circuit_options) ⇒ Object
Overring default input and output data collectors to collect/capture 1.
- .trace_output_data_collector(wrap_config, ctx, flow_options, circuit_options) ⇒ Object
Class Method Details
.arguments_for_trace(activity, ctx, original_flow_options, **circuit_options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/trailblazer/developer/wtf.rb', line 35 def arguments_for_trace(activity, (ctx, ), **) = { # this instance gets mutated with every step. unfortunately, there is # no other way in Ruby to keep the trace even when an exception was thrown. stack: Trace::Stack.new, input_data_collector: method(:trace_input_data_collector), output_data_collector: method(:trace_output_data_collector), } # Merge default options with flow_options as an order of precedence = { **, **Hash( ) } # Normalize `focus_on` param to # 1. Wrap step and variable names into an array if not already [:focus_on] = { steps: Array( .dig(:focus_on, :steps) ), variables: Array( .dig(:focus_on, :variables) ), } [activity, [ ctx, ], ] end |
.capture_variables?(step_name:, focus_on:) ⇒ Boolean
private
83 84 85 86 87 88 |
# File 'lib/trailblazer/developer/wtf.rb', line 83 def capture_variables?(step_name:, focus_on:, **) return true if focus_on[:steps].include?(step_name) # For given step return true if focus_on[:steps].empty? && focus_on[:variables].any? # For selected vars but all steps false end |
.invoke(activity, ctx, flow_options, **circuit_options) ⇒ Object
Run activity with tracing enabled and inject a mutable Stack instance. This allows to display the trace even when an exception happened
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/trailblazer/developer/wtf.rb', line 17 def invoke(activity, (ctx, ), **) activity, (ctx, ), = Wtf.arguments_for_trace( activity, [ctx, ], ** ) _returned_stack, signal, (ctx, ) = Trace.invoke( activity, [ctx, ], ** ) return signal, [ctx, ], ensure puts Trace::Present.( [:stack], renderer: Wtf::Renderer, color_map: Wtf::Renderer::DEFAULT_COLOR_MAP.merge( [:color_map] || {} ), ) end |
.trace_input_data_collector(wrap_config, ctx, flow_options, circuit_options) ⇒ Object
Overring default input and output data collectors to collect/capture
1. inspect of focusable variables for given focusable step
2. Or inspect of focused variables for all steps
61 62 63 64 65 66 67 68 69 |
# File 'lib/trailblazer/developer/wtf.rb', line 61 def trace_input_data_collector(wrap_config, (ctx, ), ) data = Trace.default_input_data_collector(wrap_config, [ctx, ], ) if Wtf.capture_variables?(step_name: data[:task_name], **) data[:focused_variables] = Trace::Focusable.capture_variables_from(ctx, **) end data end |
.trace_output_data_collector(wrap_config, ctx, flow_options, circuit_options) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/trailblazer/developer/wtf.rb', line 71 def trace_output_data_collector(wrap_config, (ctx, ), ) data = Trace.default_output_data_collector(wrap_config, [ctx, ], ) input = [:stack].top if Wtf.capture_variables?(step_name: input.data[:task_name], **) data[:focused_variables] = Trace::Focusable.capture_variables_from(ctx, **) end data end |