Module: DevSuite::MethodTracer::Helpers

Defined in:
lib/dev_suite/method_tracer/helpers.rb

Class Method Summary collapse

Class Method Details

.calculate_duration(tp, start_times) ⇒ Object



30
31
32
33
# File 'lib/dev_suite/method_tracer/helpers.rb', line 30

def calculate_duration(tp, start_times)
  start_time = start_times.delete(tp.method_id)
  start_time ? ((Time.now - start_time) * 1000.0).round(2) : nil
end

.calculate_indent(depth) ⇒ Object



35
36
37
# File 'lib/dev_suite/method_tracer/helpers.rb', line 35

def calculate_indent(depth)
  "  " * [(depth - 1), 0].max
end

.format_execution_time(duration) ⇒ Object



26
27
28
# File 'lib/dev_suite/method_tracer/helpers.rb', line 26

def format_execution_time(duration)
  duration ? " in #{duration}ms" : ""
end

.format_method_name(tp) ⇒ Object



11
12
13
# File 'lib/dev_suite/method_tracer/helpers.rb', line 11

def format_method_name(tp)
  "#{tp.defined_class}##{tp.method_id}"
end

.format_params(tp) ⇒ Object



15
16
17
18
19
20
# File 'lib/dev_suite/method_tracer/helpers.rb', line 15

def format_params(tp)
  param_values = tp.binding.local_variables.map do |var|
    tp.binding.local_variable_get(var).inspect
  end.join(", ")
  "(#{param_values})"
end

.format_result(tp) ⇒ Object



22
23
24
# File 'lib/dev_suite/method_tracer/helpers.rb', line 22

def format_result(tp)
  " #=> #{tp.return_value.inspect}"
end

.internal_call?(tp) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/dev_suite/method_tracer/helpers.rb', line 7

def internal_call?(tp)
  tp.path&.include?("<internal:") || tp.defined_class.to_s.start_with?("TracePoint")
end