pretty_debug 0.9.12 → 0.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pretty_debug.rb +31 -40
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6361f263b9b9597a906a38a65e6a2827eef13544
4
- data.tar.gz: 363663ea6cf93c53bd9a40e32c9341672ba425b4
3
+ metadata.gz: 85a94e7aa02e3d1c98c8d18337326a9173712a4b
4
+ data.tar.gz: 9bc6dc1b6e0b76c2379855beb7b8506f42d49562
5
5
  SHA512:
6
- metadata.gz: 6f452a56070f7c5a7b4ea93cb6bb9258579e633f293b68741020fe90efae273229ccd7cab86a2494d7fb6441eaf6b9751f1dfb67f46045d4ef2470b3f1ac5163
7
- data.tar.gz: 569bfde6eb5cd7adaa6171337f5657b12579c3140bb06d796ac2e0d1714c83d96175af3f24d4c0b3101d1edcf0f1a75688a19e4cadde152aaff3bf420639522b
6
+ metadata.gz: 24462db88297c904d6bc886014922ca8bed60c98a1176345a3a4467281edf7d8bd630e56e74d73191aa7181c623bcb5fc8c4d2eaa59e63cd30cf27642360df73
7
+ data.tar.gz: 51a43a899f32a2e6c5bf5c6fb8c62fe8fc8903549d0619bd0be96540ae1f8504e20531a8da8eccfd4e131b85dee42490e93d2c0ae60ff05fe9c99726986e2c48
data/lib/pretty_debug.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  #!ruby
2
2
 
3
- #############################################
4
3
  # File
5
- #############################################
6
4
 
7
5
  class File
8
6
  def self.expand_path_relative f; expand_path(f, caller_location.realdirname) end
@@ -17,9 +15,7 @@ module Kernel
17
15
  def load_relative f, *rest; load(File.expand_path(f, caller_location.realdirname), *rest) end
18
16
  end
19
17
 
20
- #############################################
21
18
  # Debug
22
- #############################################
23
19
 
24
20
  class BasicObject
25
21
  def intercept; self ensure
@@ -40,7 +36,7 @@ class Object
40
36
  mt = method(m)
41
37
  puts \
42
38
  "[Debug] #{"#{l.realpath}:#{l.lineno}"}".bf.color(:yellow),
43
- "#{self.class}(#{mt.owner})##{m}@#{mt.source_location.to_a.join(":".freeze)}"
39
+ "#{self.class}(#{mt.owner})\##{m}@#{mt.source_location.to_a.join(":".freeze)}"
44
40
  end
45
41
  end
46
42
 
@@ -103,7 +99,6 @@ class Thread::Backtrace::Location
103
99
  end
104
100
 
105
101
  module Kernel
106
- # Suppress warning message ("already initialized constants".freeze, etc.).
107
102
  def suppress_warning
108
103
  original_verbose, $VERBOSE = $VERBOSE, nil
109
104
  result = yield
@@ -111,7 +106,7 @@ module Kernel
111
106
  result
112
107
  end
113
108
  at_exit do
114
- # Terminated iterations (such as in `Sass::SyntaxError.backtrace`) overwrites `$!`.
109
+ #Gotcha# Terminated iterations (such as in `Sass::SyntaxError.backtrace`) overwrite `$!`.
115
110
  e = $!
116
111
  case e
117
112
  when nil, SystemExit, Interrupt
@@ -137,7 +132,7 @@ class PrettyDebug
137
132
  def self.format ≺ @format = pr end
138
133
  def self.message e
139
134
  e.complement_backtrace_locations
140
- e.message.to_s.dup.tap{|s| s[0] = s[0].upcase unless s.empty?}.sub(/(?<=[^.])\z/, ".".freeze)
135
+ e.message.to_s.sub(/./, &:upcase).sub(/(?<=[^.])\z/, ".".freeze).tr("'".freeze, "`".freeze)
141
136
  end
142
137
  def self.backtrace_locations e
143
138
  e.complement_backtrace_locations
@@ -192,9 +187,7 @@ end
192
187
  PrettyDebug.select{|f, m| true}
193
188
  PrettyDebug.format{|row| "#{row.join(" | ".freeze)} ".bg(:white).color(:black)}
194
189
 
195
- #############################################
196
190
  # Inspection
197
- #############################################
198
191
 
199
192
  class PrettyArray < Array
200
193
  def initialize a
@@ -202,7 +195,7 @@ class PrettyArray < Array
202
195
  reject!{
203
196
  |f, l, m|
204
197
  f == __FILE__ or
205
- m =~ /\A<.*>\z/ # Such as `<top (required)>`, `<module:Foo>`.
198
+ m =~ /\A<.*>\z/ #Purpose# Such as `<top (required)>`, `<module:Foo>`.
206
199
  }
207
200
  reject, select =
208
201
  [:@reject, :@select].map{|sym| PrettyDebug.instance_variable_get(sym)}
@@ -221,7 +214,7 @@ end
221
214
 
222
215
  class Method; def inspect; "#{receiver}.#{name}" end end
223
216
 
224
- class UnboundMethod; def inspect; "#{owner}##{name}" end end
217
+ class UnboundMethod; def inspect; "#{owner}\##{name}" end end
225
218
 
226
219
  class BasicObject
227
220
  def recursive? *; false end
@@ -245,35 +238,37 @@ class Range
245
238
  end
246
239
 
247
240
  class Array
248
- SingleLength = 50
249
- alias original_inspect inspect
250
- def inspect
251
- return original_inspect if recursive?
252
- s = map(&:inspect)
253
- length < 2 || s.map(&:length).inject(:+) < SingleLength ?
254
- "[#{s.join(", ".freeze)}]" : "[#$/#{s.join(",#$/".freeze).indent}#$/]"
241
+ module PrettyInspect
242
+ SingleLength = 50
243
+ def inspect
244
+ return super if recursive?
245
+ s = map(&:inspect)
246
+ length < 2 || s.map(&:length).inject(:+) < SingleLength ?
247
+ "[#{s.join(", ".freeze)}]" : "[#$/#{s.join(",#$/".freeze).indent}#$/]"
248
+ end
255
249
  end
250
+ prepend PrettyInspect
256
251
  end
257
252
 
258
253
  class Hash
259
- SingleLength = 50
260
- KeyLengthMax = 30
261
- alias original_inspect inspect
262
- def inspect
263
- return original_inspect if recursive?
264
- keys = self.keys.map(&:inspect)
265
- # When `self == empty?`, `...max` becomes `nil`. `to_i` turns it to `0`.
266
- w = keys.map(&:length).max.to_i
267
- w = w > KeyLengthMax ? KeyLengthMax : w
268
- s = [keys, values].transpose.map{|k, v| "#{k.ljust(w)} => #{v.inspect}"}
269
- length < 2 || s.map(&:length).inject(:+) < SingleLength ?
270
- "{#{s.join(", ".freeze)}}" : "{#$/#{s.join(",#$/".freeze).indent}#$/}"
254
+ module PrettyInspect
255
+ SingleLength = 50
256
+ KeyLengthMax = 30
257
+ def inspect
258
+ return super if recursive?
259
+ keys = keys().map(&:inspect)
260
+ #Purpose# When `self == empty?`, `...max` becomes `nil`. `to_i` turns it to `0`.
261
+ w = keys.map(&:length).max.to_i
262
+ w = w > KeyLengthMax ? KeyLengthMax : w
263
+ s = [keys, values].transpose.map{|k, v| "#{k.ljust(w)} => #{v.inspect}"}
264
+ length < 2 || s.map(&:length).inject(:+) < SingleLength ?
265
+ "{#{s.join(", ".freeze)}}" : "{#$/#{s.join(",#$/".freeze).indent}#$/}"
266
+ end
271
267
  end
268
+ prepend PrettyInspect
272
269
  end
273
270
 
274
- #############################################
275
271
  # Terminal
276
- #############################################
277
272
 
278
273
  class BasicObject
279
274
  def expand; inspect.verbatim end
@@ -291,14 +286,10 @@ class String
291
286
  {black: 0, red: 1, green: 2, yellow: 3, blue: 4, magenta: 5, cyan: 6, white: 7}[sym.to_sym]
292
287
  )}#{self}#{vt100}" end
293
288
  def de_vt100; gsub(/\e\[\d*m/, "".freeze) end
294
-
295
- private
296
- def vt100 s = "".freeze; "\e[#{s}m" end
289
+ private def vt100 s = "".freeze; "\e[#{s}m" end
297
290
  end
298
291
 
299
- #############################################
300
292
  # String Formatting
301
- #############################################
302
293
 
303
294
  class Array
304
295
  def align ellipsis_limit = nil
@@ -316,8 +307,8 @@ class Array
316
307
  i = 0
317
308
  i += 1 while first[i] and others.all?{|s| first[i] == s[i]}
318
309
  first[0, i]
319
- # This is more elegant, but cannot be generalized to `common_affix`.
320
- ## first[0, (0...first.length).find{|i| first[i].! or others.any?{|s| first[i] != s[i]}}.to_i]
310
+ ## This is more elegant, but cannot be generalized to `common_affix`.
311
+ # first[0, (0...first.length).find{|i| first[i].! or others.any?{|s| first[i] != s[i]}}.to_i]
321
312
  end
322
313
  def common_affix
323
314
  each{|e| class_check(String, e){"All elements must be a String".freeze}}
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.9.12
4
+ version: 0.9.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2015-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email: []
@@ -36,7 +36,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
36
  version: '0'
37
37
  requirements: []
38
38
  rubyforge_project:
39
- rubygems_version: 2.4.2
39
+ rubygems_version: 2.4.6
40
40
  signing_key:
41
41
  specification_version: 4
42
42
  summary: ''