Module: RequireProfiler::Printer

Defined in:
lib/require_profiler/printer.rb,
lib/require_profiler/printer/json.rb,
lib/require_profiler/printer/text.rb,
lib/require_profiler/printer/call_stack.rb

Defined Under Namespace

Classes: Base, CallStack, JSON, Text

Class Method Summary collapse

Class Method Details

.resolve(output, format, **opts) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/require_profiler/printer.rb', line 46

def resolve(output, format, **opts)
  format ||= (output.is_a?(String) && File.extname(output) == ".json") ? :json : :text
  output = File.open(output, "w+") if output.is_a?(String)

  case format.to_sym
  when :json then JSON.new(output, **opts)
  when :call_stack then CallStack.new(output, **opts)
  when :text then Text.new(output, **opts)
  else
    raise ArgumentError, "Unknown format specified: #{format}. Available formats: text, json, call_stack"
  end
end