Class: PrettyDebug
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
- .backtrace_locations(e) ⇒ Object
- .beautify(a) ⇒ Object
- .caller_locations ⇒ Object
- .format(&pr) ⇒ Object
- .message(e) ⇒ Object
- .message_format(&pr) ⇒ Object
- .reject(&pr) ⇒ Object
- .select(&pr) ⇒ Object
Class Method Details
.backtrace_locations(e) ⇒ Object
137 138 139 140 |
# File 'lib/pretty_debug.rb', line 137 def self.backtrace_locations e e.complement_backtrace_locations PrettyArray.new(beautify(e.backtrace_locations)) end |
.beautify(a) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/pretty_debug.rb', line 162 def self.beautify a 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 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_locations ⇒ Object
141 142 143 |
# File 'lib/pretty_debug.rb', line 141 def self.caller_locations PrettyArray.new(beautify(Kernel.caller_locations)) end |
.format(&pr) ⇒ Object
125 |
# File 'lib/pretty_debug.rb', line 125 def self.format ≺ @format = pr end |
.message(e) ⇒ Object
133 134 135 136 |
# File 'lib/pretty_debug.rb', line 133 def self. e e.complement_backtrace_locations e..dup.tap{|s| s[0] = s[0].upcase unless s.empty?}.sub(/(?<=[^.])\z/, ".".freeze) end |
.message_format(&pr) ⇒ Object
126 |
# File 'lib/pretty_debug.rb', line 126 def self. ≺ @message_formar = pr end |
.reject(&pr) ⇒ Object
117 118 119 120 |
# File 'lib/pretty_debug.rb', line 117 def self.reject &pr reject = @reject @reject = ->(*args){reject.call(*args) or pr.call(*args)} end |
.select(&pr) ⇒ Object
121 122 123 124 |
# File 'lib/pretty_debug.rb', line 121 def self.select &pr select = @select @select = ->(*args){select.call(*args) or pr.call(*args)} end |