pretty_debug 0.3.12 → 0.3.13

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 +83 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 880e84fa86195e096990ca5457a1008c2dfc6931
4
- data.tar.gz: 5b99c798a66fb358988bdecb21085da69fd1b46a
3
+ metadata.gz: e25d6a8b6da79b8366241bf88cad7f841bc775eb
4
+ data.tar.gz: d6db434114fdc8e46a99ef799282d9c057398c0f
5
5
  SHA512:
6
- metadata.gz: 29da74764409a181d959fd87054bbaab909c8514baf6cf2abf68b7db4ec9cae16eb5342bedf499572a6edf5b6219526843b9afdad7c3e899d7d86372dacb5744
7
- data.tar.gz: 549932a814ee2fa313b7d930283aaeb67c75aa5d71e71a7ced9be6239b2c3fa646271f3d1e723038d019dea72a13b123c91e2983051d6a3f03c9f222150b36c9
6
+ metadata.gz: 2d51fd3e149f798e85e1a491327e5ba5882e012fca1f250f4acd8c5459fefcb5353d65dc21526bfbde659612219d3eabdab41c9c7bf0a592a706341534e3aa28
7
+ data.tar.gz: 6a74c14b61b2ad0f54b3ac82a0aaf670f576057cd62ead6f6f7ea009a1386abed8ff0995cab57175220572fda034d9479cdc0984e6950f79027f1b2032ce6217
data/lib/pretty_debug.rb CHANGED
@@ -1,7 +1,74 @@
1
1
  #!ruby
2
- require "string"
3
2
  require "utility"
4
3
 
4
+ #############################################
5
+ # File
6
+ #############################################
7
+
8
+ class File
9
+ def self.relativize f; f.sub(%r{\A/}, "") end
10
+ def self.expand_path_relative f; expand_path(f, caller_location(1).dirname) end
11
+ end
12
+
13
+ class Dir
14
+ def self.glob_relative f; glob(File.expand_path(f, caller_location(1).dirname)) end
15
+ end
16
+
17
+ module Kernel
18
+ def caller_location i; caller_locations(i + 1, 1).first end
19
+ def load_relative f, *rest;
20
+ load(File.expand_path(f, caller_location(1).dirname), *rest)
21
+ end
22
+ end
23
+
24
+ #############################################
25
+ # String
26
+ #############################################
27
+
28
+ class String
29
+ @@indent = " "
30
+ def indent n = 1; gsub(/^/, @@indent * n) end
31
+ def unindent; gsub(/^#{match(/^\s+/)}/, "").chomp end
32
+ def unchomp; sub(/#$/?\z/, $/) end
33
+ def unchomp!; sub!(/#$/?\z/, $/) end
34
+ def ellipsis n
35
+ if length <= n then self
36
+ elsif n.odd? then "#{slice(0..n/2-3)}...#{slice(-n/2+2..-1)}"
37
+ else "#{slice(0..n/2-3)}...#{slice(-n/2+1..-1)}"
38
+ end
39
+ end
40
+ def common_prefix other
41
+ i = 0
42
+ loop{break unless self[i] and self[i] == other[i]; i += 1}
43
+ self[0, i]
44
+ end
45
+ def common_affix other
46
+ i = - 1
47
+ loop{break unless self[i] and self[i] == other[i]; i -= 1}
48
+ self[i + 1, -(i + 1)]
49
+ end
50
+ def write_to f; write_to!(f) rescue nil end
51
+ def write_to! f; File.write(f, self) end
52
+ def binary_write_to f; binary_write_to!(f) rescue nil end
53
+ def binary_write_to! f; File.write(f, self, "wb") end
54
+ def add_to f; add_to!(f) rescue nil end
55
+ def add_to! f; File.open(f, "a+") do |io|
56
+ io.readlines.last.tap{|l| io.puts if l && l.end_with?($/).!}
57
+ io.write(self)
58
+ end
59
+ end
60
+ # Raises an error if either save, read, or round-trip-matching fails.
61
+ def safely_write_to dest, tmp = "#{Dir.tmpdir}/safe-save"
62
+ write_to!(tmp)
63
+ raise "Round trip `save-read` failed on `#{dest}`." unless File.read(tmp) == self
64
+ File.rename(tmp, dest)
65
+ end
66
+ end
67
+
68
+ #############################################
69
+ #
70
+ #############################################
71
+
5
72
  class Exception
6
73
  attr_accessor :backtrace_locations
7
74
  def complement_backtrace_locations
@@ -22,8 +89,21 @@ class Thread::Backtrace::PseudoLocation
22
89
  end
23
90
  end
24
91
 
92
+ class Thread::Backtrace::Location
93
+ def dirname; File.dirname(path) end
94
+ def basename; File.basename(path) end
95
+ end
96
+
25
97
  module Kernel
26
- alias old_raise :raise
98
+ ## Supress warning message ("already initialized constants", etc.).
99
+ def supress_warning
100
+ original_verbose, $VERBOSE = $VERBOSE, nil
101
+ yield
102
+ $VERBOSE = original_verbose
103
+ end
104
+ ErrorMsgProcess = Mutex.new
105
+ def log h; ErrorMsgProcess.synchronize{puts(h.ltsv)} end
106
+ alias old_raise :raise unless defined?(old_raise)
27
107
  def raise *args
28
108
  old_raise *args
29
109
  rescue => e
@@ -150,12 +230,7 @@ end
150
230
  #############################################
151
231
 
152
232
  class Hash
153
- def ltsv *args
154
- if args.empty? then
155
- map{|k, v| "#{k}:#{v.to_s.tr("\t", " ")}"} else
156
- args.map{|k| "#{k}:#{self[k].to_s.tr("\t", " ")}"}
157
- end.join("\t")
158
- end
233
+ def ltsv; map{|k, v| "#{k}:#{v.to_s.tr("\t", " ")}"}.join("\t") end
159
234
  end
160
235
  class String
161
236
  def parse_ltsv; Hash[chomp.split("\t").map{|f| f.split(":", 2)}] 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.3.12
4
+ version: 0.3.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-18 00:00:00.000000000 Z
11
+ date: 2013-09-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email: []