Class: PrettyDebug

Inherits:
Object show all
Defined in:
lib/pretty_debug.rb

Constant Summary collapse

Hook =
%w[
  at_exit
  set_trace_func
  initialize
  method_missing
  singleton_method_added
  singleton_method_removed
  singleton_method_undefined
  respond_to_missing?
  extended
  included
  method_added
  method_removed
  method_undefined
  const_missing
  inherited
  intitialize_copy
  intitialize_clone
  intitialize_dup
  prepend
  append_features
  extend_features
  prepend_features
]

Class Method Summary collapse

Class Method Details

.backtrace_locations(e) ⇒ Object



126
127
128
129
# File 'lib/pretty_debug.rb', line 126

def self.backtrace_locations e
  e.complement_backtrace_locations
  PrettyArray.new(beautify(e.backtrace_locations))
end

.beautify(a) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/pretty_debug.rb', line 157

def self.beautify a
  a
  .map{|l| [l.realpath, l.lineno, l.label]}
  .transpose.tap do |_, _, ms|
    ms.map! do |m|
      case m
      when *Hook then "(#{m})"
      when /\A(rescue in )?block( .*)? in / then "(entered block)".freeze
      when /\Arescue in / then "".freeze
      else m
      end
    end
    ms[-1] = "".freeze; ms.rotate!(-1)
  end.transpose
end

.caller_locationsObject



130
131
132
# File 'lib/pretty_debug.rb', line 130

def self.caller_locations
  PrettyArray.new(beautify(Kernel.caller_locations))
end

.format(&pr) ⇒ Object



121
# File 'lib/pretty_debug.rb', line 121

def self.format ≺ @format = pr end

.message(e) ⇒ Object



122
123
124
125
# File 'lib/pretty_debug.rb', line 122

def self.message e
  e.complement_backtrace_locations
  e.message.dup.tap{|s| s[0] = s[0].upcase unless s.empty?}.sub(/(?<=[^.])\z/, ".".freeze)
end

.reject(&pr) ⇒ Object



113
114
115
116
# File 'lib/pretty_debug.rb', line 113

def self.reject &pr
  @reject = pr
  @select = ->f, m{true}
end

.select(&pr) ⇒ Object



117
118
119
120
# File 'lib/pretty_debug.rb', line 117

def self.select &pr
  @select = pr
  @reject = ->f, m{false}
end