Sha256: 406948cbd8c7eafe2dcef5274d9d29ccd427b3b3e0d91de97f4ecb0216926f6c

Contents?: true

Size: 819 Bytes

Versions: 1

Compression:

Stored size: 819 Bytes

Contents

# frozen_string_literal: true

# encoding=utf-8

require 'json'
require 'yaml'

require_relative 'env'
include Env

## application-level debug control
#
module Tap
  $tap_enable = env_bool 'TAP_DEBUG'

  def tap_config(enable: nil, envvar: nil, value: nil)
    $tap_enable = if envvar
                    env_bool envvar
                  elsif value
                    value.to_i != 0
                  elsif enable
                    enable
                  end
  end

  def tap_inspect(format: nil, name: 'return')
    return self unless $tap_enable

    cvt = {
      json: :to_json,
      string: :to_s,
      yaml: :to_yaml,
      else: :inspect
    }
    fn = cvt.fetch(format, cvt[:else])

    puts "-> #{caller[0].scan(/in `?(\S+)'$/)[0][0]}()" \
         " #{name}: #{method(fn).call}"

    self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
markdown_exec-1.3.0 lib/tap.rb