Module: Tap

Includes:
Env
Defined in:
lib/tap.rb

Overview

application-level debug control

:reek:TooManyConstants

Constant Summary collapse

DN =
'return'
NONE =
0x0
T1 =

RESULT

1
T2 =

CONTEXT

2
T3 =

MONITOR

4
T4 =

DUMP

8
ALL2 =
0x77
ALL =
0xFF
TDD =
0x11
TB1 =
0x22
TB2 =
0x44
TB3 =
0x88
TD =
0x0F
TD0 =
0x01
TD1 =
0x02
TD2 =
0x04
TP =
0xF0
TP0 =
0x10
TP1 =
0x20
TP2 =
0x40
CVT =

cast with message per tap_inspect type type: message

{
  json: :to_json,
  string: :to_s,
  yaml: :to_yaml,
  else: :inspect
}.freeze

Instance Method Summary collapse

Methods included from Env

#env_bool, #env_bool_false, #env_int, #env_str

Instance Method Details

#tap_config(enable: true, envvar: nil, value: nil) ⇒ Object

:reek:BooleanParameter :reek:ControlParameter



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/tap.rb', line 82

def tap_config(enable: true, envvar: nil, value: nil)
  $tap_enable = false
  if envvar
    $tap_enable = (env_int envvar).positive?
    $tap_mask = ALL2 if $tap_enable
  elsif value
    $tap_mask = value.to_i
    $tap_enable = $tap_mask.positive?
  elsif enable
    $tap_mask = ALL2
    $tap_enable = true
  end
  # puts "$tap_enable: #{$tap_enable}"
  # puts "$tap_mask: #{$tap_mask.to_s(2)}"
  self
end

#tap_inspect(name_ = nil, caller_first: nil, mask: TDD, name: DN, source: nil, type: nil) ⇒ Object

:reek:ControlParameter :reek:LongParameterList



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/tap.rb', line 101

def tap_inspect(name_ = nil, caller_first: nil, mask: TDD, name: DN, source: nil,
                type: nil)
  return self unless $tap_enable
  return self unless (mask & $tap_mask).positive?

  fn = CVT.fetch(type, CVT[:else])
  outs = []
  outs.push(source.to_s) if source.present?

  vs = (caller_first || caller[0]).scan(/in `?(\S+)'$/).fetch(0, []).fetch(0, '')
  outs.push("#{vs}()") if vs.present?

  outs.push(tap_named_value(name_ || name, method(fn).call))

  $stdout.puts(outs.join(' ')) if outs.length.positive?
  self
end

#tap_print(mask: TDD) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/tap.rb', line 119

def tap_print(mask: TDD)
  return self unless $tap_enable
  return self unless (mask & $tap_mask).positive?

  $stdout.print self
  self
end

#tap_pryObject



127
128
129
130
131
132
# File 'lib/tap.rb', line 127

def tap_pry
  return self unless $tap_enable

  binding.pry
  self
end

#tap_puts(name_ = nil, mask: TDD, name: nil) ⇒ Object

:reek:ControlParameter



135
136
137
138
139
140
141
# File 'lib/tap.rb', line 135

def tap_puts(name_ = nil, mask: TDD, name: nil)
  return self unless $tap_enable
  return self unless (mask & $tap_mask).positive?

  $stdout.puts tap_named_value(name_ || name, self)
  self
end

#tap_yaml(name_ = nil, caller_first: nil, mask: TDD, name: DN, source: nil) ⇒ Object

:reek:ControlParameter :reek:LongParameterList



145
146
147
148
# File 'lib/tap.rb', line 145

def tap_yaml(name_ = nil, caller_first: nil, mask: TDD, name: DN, source: nil)
  tap_inspect name_, caller_first: (caller_first || caller[0]),
                     mask: mask, name: name, source: source, type: :yaml
end