Sha256: e9526b036ec255215b26a201819af463c9d6dadaff019938d30aff86cc847744

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

# encoding=utf-8
require 'pp'

$debug = $DEBUG || !ENV['WW'].nil?

# attribution in output unless disabled
if $debug && ENV['WW_MINIMUM'].nil?
  $stderr.puts "WW Debugging per $DEBUG ('ruby --debug')" if $DEBUG
  $stderr.puts "WW Debugging per environment variable WW" if !ENV['WW'].nil?
end

# def wtr(*objs, full_backtrace: false, single_line: false)
#   ww(['->'] + objs,
#      locations: caller_locations[2..-1],
#      full_backtrace: full_backtrace,
#      single_line: single_line)
# end

def ww(*objs, full_backtrace: false, single_line: false,
       locations: caller_locations)
  return unless $debug

  def cil(caller_info)
    "#{caller_info.lineno} : #{File.basename(caller_info.path)} : " \
      "#{caller_info.label}"
  end

  backtrace = if full_backtrace
                locations.map do |caller_info|
                  cil(caller_info)
                end
              else
                [cil(locations[0, 1].first)]
              end
  trace = backtrace + objs
  if single_line
    PP.singleline_pp(trace, $stderr)
  else
    PP.pp(trace, $stderr)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
markdown_exec-2.5.0 lib/ww.rb