Class: PrettyDebug

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

Constant Summary collapse

Hook =
%w[
  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
]

Class Method Summary collapse

Class Method Details

.backtrace_locations(e) ⇒ Object



152
153
154
155
# File 'lib/pretty_debug.rb', line 152

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

.beautify(a) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/pretty_debug.rb', line 177

def self.beautify a
  a = a
  .map{|l| [l.absolute_path, 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)"
      when /\Arescue in / then ""
      else m
      end
    end
    ms[-1] = ""; ms.rotate!(-1)
  end.transpose
  a.reject!{|f, l, m| @reject.call(f, m)} rescue nil
  a.select!{|f, l, m| @select.call(f, m)} rescue nil
  a
end

.caller_locationsObject



156
157
158
# File 'lib/pretty_debug.rb', line 156

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

.format(&pr) ⇒ Object



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

def self.format ≺ @format = pr end

.message(e) ⇒ Object



148
149
150
151
# File 'lib/pretty_debug.rb', line 148

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

.reject(&pr) ⇒ Object



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

def self.reject &pr; @reject += pr end

.select(&pr) ⇒ Object



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

def self.select &pr; @select += pr end