pretty_debug 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pretty_debug.rb +13 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6fef9338276578fa99842e75229d0603199b534
4
- data.tar.gz: 16419c3856e68720c6f6174113ce23e9e81801fc
3
+ metadata.gz: 586a6a3bbcec2fd560dec4af52d338f2f8276b92
4
+ data.tar.gz: 29a97950744e70acaf157ea78a7d949d231cd7a0
5
5
  SHA512:
6
- metadata.gz: 6103195bfab4700a63c8ee4d933ad3fe2c73f84cd31830ce337daa6cfb6a11dd65bfd19fde2cd77839305cc8362c6dc3bf36668fe026a0fac97c4e90b2a4ced1
7
- data.tar.gz: ace06c28be584d84879e2623b03a4568c7a0ea9e7b749da977fd89ac4cc65845dc963a90444cda6aac35b56fa5b215ada0db8d36c4b387696513568a2a7ad417
6
+ metadata.gz: 2c85006d3881f2b1ae1d4b5c767e64b9fdaa3f1f6426bf6ae64171be88292c5ddf97ce763ba1118dabf6d3e488a9e722f62c7dc3b1af85a01d456ef764ea0f12
7
+ data.tar.gz: ac303b059e31df106d595778a220477705d86c76bc4a51eb7c6b19fca0b7c3bf661ad1d26bbdd509108531d3ed0c0832c34d6844a69d40bd7f292d52c9ba0094
data/lib/pretty_debug.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  #!ruby
2
2
  require "tmpdir"
3
3
  require "compact_time"
4
- require "utility"
5
4
 
6
5
  #############################################
7
6
  # File
@@ -86,8 +85,8 @@ class Thread::Backtrace::PseudoLocation
86
85
  attr_accessor :to_s, :absolute_path, :lineno, :label, :path, :base_label
87
86
  def initialize to_s
88
87
  @to_s = to_s
89
- @absolute_path, @lineno, @label =
90
- @to_s.match(Pattern).chain{|m| [m[:f], m[:l].chain{|l| l.to_i if l}, m[:m].to_s]}
88
+ m = @to_s.match(Pattern)
89
+ @absolute_path, @lineno, @label = m[:f], m[:l] ? m[:l].to_i : nil, m[:m].to_s
91
90
  @path = File.basename(@absolute_path)
92
91
  @base_label = @label
93
92
  end
@@ -212,16 +211,16 @@ class UnboundMethod; def inspect; "#{owner}##{name}" end end
212
211
  class Array
213
212
  SingleLength = 50
214
213
  def inspect
215
- map(&:inspect)
216
- .chain{|s| length < 2 || s.map(&:length).inject(:+) < SingleLength ?
217
- "[#{s.join(", ".freeze)}]" : "[#$/#{s.join(",#$/".freeze).indent}#$/]"}
214
+ s = map(&:inspect)
215
+ length < 2 || s.map(&:length).inject(:+) < SingleLength ?
216
+ "[#{s.join(", ".freeze)}]" : "[#$/#{s.join(",#$/".freeze).indent}#$/]"
218
217
  end
219
218
  def align ellipsis_limit = nil
220
219
  transpose.map do |col|
221
220
  just = case col.first; when Numeric then :rjust; else :ljust end
222
221
  width = col.map{|cell| cell.to_s.length}.max
223
222
  max = ellipsis_limit || width
224
- col.map{|cell| cell.to_s.ellipsis(max).__send__(just, width.at_most(max))}
223
+ col.map{|cell| cell.to_s.ellipsis(max).__send__(just, width > max ? max : width)}
225
224
  end.transpose
226
225
  end
227
226
  def common_prefix
@@ -246,17 +245,19 @@ class Hash
246
245
  def inspect
247
246
  keys = self.keys.map(&:inspect)
248
247
  # When `self == empty?`, `...max` becomes `nil`. `to_i` turns it to `0`.
249
- w = keys.map(&:length).max.to_i.at_most(KeyLengthMax)
250
- [keys, values].transpose.map{|k, v| "#{k.ljust(w)} => #{v.inspect}"}
251
- .chain{|s| length < 2 || s.map(&:length).inject(:+) < SingleLength ?
252
- "{#{s.join(", ".freeze)}}" : "{#$/#{s.join(",#$/".freeze).indent}#$/}"}
248
+ w = keys.map(&:length).max.to_i
249
+ w = w > KeyLengthMax ? KeyLengthMax : w
250
+ s = [keys, values].transpose.map{|k, v| "#{k.ljust(w)} => #{v.inspect}"}
251
+ length < 2 || s.map(&:length).inject(:+) < SingleLength ?
252
+ "{#{s.join(", ".freeze)}}" : "{#$/#{s.join(",#$/".freeze).indent}#$/}"
253
253
  end
254
254
  end
255
255
 
256
256
  class Object
257
257
  def intercept &pr
258
+ l = caller_location(3)
258
259
  tap do |x| puts \
259
- "[Debug] #{caller_location(3).chain{|l| "#{l.path}:#{l.lineno}"}}".color(:yellow),
260
+ "[Debug] #{"#{l.path}:#{l.lineno}"}".color(:yellow),
260
261
  (pr ? pr.call(x) : x).inspect.verbatim.unchomp
261
262
  end
262
263
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pretty_debug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-04 00:00:00.000000000 Z
11
+ date: 2014-01-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email: []