rmtools 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +84 -26
  3. data/Rakefile +7 -4
  4. data/ext/extconf.rb +1 -1
  5. data/ext/rmtools.cpp +27 -12
  6. data/ext/rmtools.h +6 -5
  7. data/lib/rmtools/b.rb +18 -0
  8. data/lib/rmtools/console/coloring.rb +72 -0
  9. data/lib/rmtools/console/highlight.rb +13 -0
  10. data/lib/rmtools/{printing.rb → console/printing.rb} +17 -2
  11. data/lib/rmtools/console.rb +1 -0
  12. data/lib/rmtools/conversions/enum.rb +23 -0
  13. data/lib/rmtools/conversions/int.rb +47 -0
  14. data/lib/rmtools/conversions/string.rb +26 -0
  15. data/lib/rmtools/conversions.rb +1 -0
  16. data/lib/rmtools/core/arguments.rb +52 -0
  17. data/lib/rmtools/{boolean.rb → core/boolean.rb} +0 -13
  18. data/lib/rmtools/core/class.rb +41 -0
  19. data/lib/rmtools/core/js.rb +45 -0
  20. data/lib/rmtools/core/kernel.rb +28 -0
  21. data/lib/rmtools/{module.rb → core/module.rb} +0 -41
  22. data/lib/rmtools/core/numeric.rb +35 -0
  23. data/lib/rmtools/{object.rb → core/object.rb} +2 -23
  24. data/lib/rmtools/core/proc.rb +18 -0
  25. data/lib/rmtools/core/regexp.rb +11 -0
  26. data/lib/rmtools/core/string_compliance.rb +31 -0
  27. data/lib/rmtools/core.rb +1 -0
  28. data/lib/rmtools/db/active_record.rb +54 -0
  29. data/lib/rmtools/db.rb +7 -0
  30. data/lib/rmtools/debug/binding.rb +56 -0
  31. data/lib/rmtools/debug/highlight.rb +23 -0
  32. data/lib/rmtools/debug/logging.rb +176 -0
  33. data/lib/rmtools/debug/present.rb +38 -0
  34. data/lib/rmtools/debug/timer.rb +19 -0
  35. data/lib/rmtools/debug/traceback.rb +92 -0
  36. data/lib/rmtools/debug.rb +1 -0
  37. data/lib/rmtools/debug_notrace.rb +1 -0
  38. data/lib/rmtools/enumerable/array.rb +134 -0
  39. data/lib/rmtools/enumerable/array_iterators.rb +33 -0
  40. data/lib/rmtools/enumerable/common.rb +49 -0
  41. data/lib/rmtools/{hash.rb → enumerable/hash.rb} +8 -8
  42. data/lib/rmtools/enumerable/object_space.rb +19 -0
  43. data/lib/rmtools/enumerable/range.rb +201 -0
  44. data/lib/rmtools/enumerable.rb +1 -0
  45. data/lib/rmtools/experimental/blackhole.rb +12 -0
  46. data/lib/rmtools/experimental/deprecation.rb +36 -0
  47. data/lib/rmtools/experimental/dumps.rb +28 -0
  48. data/lib/rmtools/{numeric.rb → experimental/numeric.rb} +22 -51
  49. data/lib/rmtools/experimental/rails_backtrace.rb +29 -0
  50. data/lib/rmtools/experimental/string.rb +56 -0
  51. data/lib/rmtools/{tree.rb → experimental/tree.rb} +0 -0
  52. data/lib/rmtools/experimental.rb +1 -0
  53. data/lib/rmtools/fs/dir.rb +89 -0
  54. data/lib/rmtools/fs/file.rb +104 -0
  55. data/lib/rmtools/fs/io.rb +58 -0
  56. data/lib/rmtools/fs/tools.rb +49 -0
  57. data/lib/rmtools/fs.rb +1 -0
  58. data/lib/rmtools/functional/fold.rb +32 -0
  59. data/lib/rmtools/{string_to_proc.rb → functional/string_to_proc.rb} +2 -22
  60. data/lib/rmtools/functional/unfold.rb +16 -0
  61. data/lib/rmtools/functional.rb +1 -0
  62. data/lib/rmtools/ip/numeric.rb +35 -0
  63. data/lib/rmtools/ip/string.rb +45 -0
  64. data/lib/rmtools/ip.rb +1 -0
  65. data/lib/rmtools/lang/ansi.rb +17 -0
  66. data/lib/rmtools/lang/cyrillic.rb +106 -0
  67. data/lib/rmtools/lang/regexp.rb +8 -0
  68. data/lib/rmtools/lang/shortcuts.rb +20 -0
  69. data/lib/rmtools/lang.rb +1 -0
  70. data/lib/rmtools/rand/array.rb +39 -0
  71. data/lib/rmtools/rand/enum.rb +26 -0
  72. data/lib/rmtools/rand/range.rb +13 -0
  73. data/lib/rmtools/{random.rb → rand/string.rb} +13 -107
  74. data/lib/rmtools/rand.rb +1 -0
  75. data/lib/rmtools/require.rb +13 -0
  76. data/lib/rmtools/setup.rb +6 -5
  77. data/lib/rmtools/text/string_parse.rb +60 -0
  78. data/lib/rmtools/{stringscanner.rb → text/string_scanner.rb} +3 -2
  79. data/lib/rmtools/text/string_simple.rb +75 -0
  80. data/lib/rmtools/text/string_split.rb +148 -0
  81. data/lib/rmtools/text/textilize.rb +44 -0
  82. data/lib/rmtools/text.rb +1 -0
  83. data/lib/rmtools/time/global.rb +17 -0
  84. data/lib/rmtools/time/russian.rb +47 -0
  85. data/lib/rmtools/time.rb +1 -32
  86. data/lib/rmtools/xml/document.rb +28 -0
  87. data/lib/rmtools/xml/finders.rb +84 -0
  88. data/lib/rmtools/xml/libxml.rb +11 -0
  89. data/lib/rmtools/xml/node.rb +196 -0
  90. data/lib/rmtools/xml/string.rb +43 -0
  91. data/lib/rmtools/xml/xpath.rb +32 -0
  92. data/lib/rmtools/xml.rb +7 -0
  93. data/lib/rmtools.rb +8 -44
  94. metadata +97 -72
  95. data/lib/rmtools/arguments.rb +0 -24
  96. data/lib/rmtools/array.rb +0 -189
  97. data/lib/rmtools/binding.rb +0 -23
  98. data/lib/rmtools/coloring.rb +0 -82
  99. data/lib/rmtools/cyr-time.rb +0 -49
  100. data/lib/rmtools/cyrilic.rb +0 -124
  101. data/lib/rmtools/dumps.rb +0 -192
  102. data/lib/rmtools/enum.rb +0 -90
  103. data/lib/rmtools/io.rb +0 -303
  104. data/lib/rmtools/js.rb +0 -25
  105. data/lib/rmtools/limited_string.rb +0 -17
  106. data/lib/rmtools/logging.rb +0 -158
  107. data/lib/rmtools/proc.rb +0 -25
  108. data/lib/rmtools/range.rb +0 -100
  109. data/lib/rmtools/string.rb +0 -276
  110. data/lib/rmtools/traceback.rb +0 -106
@@ -1,276 +0,0 @@
1
- # encoding: utf-8
2
- class String
3
- if !method_defined? :/
4
- alias :/ :split
5
- end
6
-
7
- def inline
8
- count("\n") == 0
9
- end
10
-
11
- def <<(str)
12
- concat str.to_s
13
- end
14
-
15
- # %{blah blah
16
- # wall of text in the interpreter
17
- # oh shi~ may be we should
18
- # save this into variable
19
- # } >> (str='')
20
- # ok, easily saved to variable
21
- def >>(str)
22
- str.replace(self + str)
23
- end
24
-
25
- def find_with_offsets text, offset
26
- index = index(text)
27
- start = [0, index - offset].max
28
- _end = index + text.size
29
- [self[start...index], text, self[_end, offset]]
30
- end
31
-
32
- def div(dvsr, includesplitter=1, reportheaders=nil)
33
- return lendiv dvsr if dvsr.kinda Fixnum
34
- a = split(dvsr)
35
- return a if !includesplitter and !reportheaders
36
- skan = nil
37
- case dvsr
38
- when String
39
- a = (1...a.size).map {|i| dvsr+a[i]}.unshift a[0] if includesplitter
40
- when Regexp
41
- skan = scan(dvsr).unshift ''
42
- a = (0...a.size).map {|i| skan[i].to_s+a[i]} if includesplitter
43
- end
44
- (reportheaders and skan) ? [a, skan] : a
45
- end
46
-
47
- def rdiv(dvsr, includesplitter=1, reportheaders=nil)
48
- return lendiv dvsr if dvsr.kinda Fixnum
49
- a = split(dvsr)
50
- return a if !includesplitter and !reportheaders
51
- skan = nil
52
- case dvsr
53
- when String
54
- a = (0...a.size).map {|i| a[i]+dvsr} if includesplitter
55
- when Regexp
56
- skan = scan(dvsr)
57
- a = (0...a.size).map {|i| a[i]+skan[i]} if includesplitter
58
- end
59
- (reportheaders and skan) ? [a, skan] : a
60
- end
61
-
62
- def lendiv(len)
63
- return [self] if len <= 0
64
- str = dup
65
- arr = []
66
- while str.b
67
- arr << str.slice!(0, len)
68
- end
69
- arr
70
- end
71
-
72
- def split_to_lines(maxlen, charsize=nil, no_blanks=false, strips=true)
73
- raise Exception, "Can't break text with maxlen = #{maxlen}" if maxlen < 1
74
- a = split("\n")
75
- charsize ||= a[0].cyr? ? 2 : 1
76
- a.map {|string| string.strip.split_to_blocks(maxlen*charsize, nil, false, no_blanks, strips)}.flatten*"\n"
77
- end
78
-
79
- def split_to_blocks(maxlen, terminator=nil, strict_overhead=true, no_blanks=true, strips=false)
80
- raise Exception, "Can't break text with maxlen = #{maxlen}" if maxlen < 1
81
- blocks = []
82
- term_re = /[^#{terminator}]+\z/ if terminator and terminator != :syntax
83
- return [self] if size <= maxlen
84
- words, buf = split(strips ? ' ' : / /), nil
85
- while words.b or buf.b
86
- if terminator and blocks.b and (buf_add = if terminator == :syntax
87
- blocks[-1].split_by_syntax maxlen, buf.size
88
- else blocks[-1][term_re]
89
- end.b)
90
- if buf_add == blocks[-1]
91
- blocks.pop
92
- else blocks[-1] = blocks[-1][0...-buf_add.size]
93
- end
94
- buf = buf_add + buf
95
- end
96
- blocks << ''
97
- if buf
98
- blocks[-1] << buf
99
- buf = nil
100
- end
101
- while words.b
102
- buf = words.shift + ' '
103
- break if blocks[-1].size + buf.size - 1 > maxlen
104
- blocks[-1] << buf
105
- buf = nil
106
- end
107
- end
108
- blocks.reject! &:empty? if no_blanks
109
- blocks.strips! if strips
110
- blocks.each {|b| raise Exception, "can't split string by #{terminator} to blocks with max length = #{maxlen}" if b.size > maxlen} if strict_overhead
111
- blocks
112
- end
113
-
114
- RMTools::URL_RE = %r{^((?:([^:]+)://)#{ # ( protocol
115
- }([^/:]*(?::(\d+))?))?#{ # root[:port] )
116
- }((/[^?#]*?(?:\.(\w+))?)#{ # ( path[.fileext]
117
- }(?:\?(.*?))?)?#{ # [?query params] )
118
- }(?:#(.+))?#{ # [ #anchor ]
119
- }$} unless defined? RMTools::URL_RE
120
- def parseuri
121
- m = match RMTools::URL_RE
122
- !m || m[0].empty? ?
123
- { 'href' => self } :
124
- { 'href' => self,
125
- 'root' => m[1],
126
- 'protocol' => m[2],
127
- 'host' => m[3],
128
- 'port' => m[4] ? m[4].to_i : 80,
129
- 'fullpath' => m[5] || '/',
130
- 'pathname' => m[5] || '/',
131
- 'path' => m[6] || '',
132
- 'ext' => m[7],
133
- 'query' => m[8] && m[8].to_hash(false),
134
- 'anchor' => m[9] }
135
- end
136
-
137
- def utf(from_encoding)
138
- Iconv.new('UTF-8', from_encoding).iconv(self)
139
- end
140
-
141
- def utf!(from_encoding)
142
- replace utf from_encoding
143
- end
144
-
145
- def bytes
146
- arr = []
147
- each_byte {|b| arr << "\\x#{b.hex}"}
148
- arr
149
- end
150
-
151
- def to_re(esc=false)
152
- Regexp.new(esc ? Regexp.escape(self) : self)
153
- end
154
-
155
- def lchomp(match)
156
- if index(match) == 0
157
- self[match.size..-1]
158
- else
159
- self.dup
160
- end
161
- end
162
-
163
- def lchomp!(match)
164
- if index(match) == 0
165
- self[0...match.size] = ''
166
- self
167
- end
168
- end
169
-
170
- def rsplit(splitter=$/, qty=0)
171
- reverse.split(splitter, qty).reverse.reverses
172
- end
173
-
174
- def until(splitter=$/)
175
- split(splitter, 2)[0]
176
- end
177
- alias :till :until
178
-
179
- def after(splitter=$/)
180
- split(splitter, 2)[1]
181
- end
182
-
183
- def bump_version(splt='.')
184
- re = /(?:(\d*)#{Regexp.escape splt})?/
185
- s = File.split self
186
- s[0] == '.' ?
187
- s[1].reverse.sub(re) {$1?"#{$1.to_i+1}#{splt}":"1#{splt}"}.reverse :
188
- File.join(s[0], s[1].reverse.sub(re) {$1?"#{$1.to_i+1}#{splt}":"1#{splt}"}.reverse)
189
- end
190
- alias :next_version :bump_version
191
-
192
- def bump!(splt='.')
193
- replace bump_version splt
194
- end
195
-
196
- if RUBY_VERSION < "1.9"
197
- def ord; self[0] end
198
- else
199
- # BUGFIX?
200
- alias :sub19 :sub
201
- alias :sub19! :sub!
202
- alias :gsub19 :gsub
203
- alias :gsub19! :gsub!
204
-
205
- def sub! a,b=nil,&c
206
- if b
207
- if b=~/\\\d/
208
- b = b.sub19!(/\\\d/) {|m| "\#{$#{m[1,1]}}"}
209
- sub19!(a) {eval "\"#{b}\""}
210
- else sub19!(a) {b} end
211
- else sub19! a,&c end
212
- end
213
-
214
- def sub a,b=nil,&c
215
- if b
216
- if b=~/\\\d/
217
- b = b.sub19(/\\\d/) {|m| "\#{$#{m[1,1]}}"}
218
- sub19(a) {eval "\"#{b}\""}
219
- else sub19(a) {b} end
220
- else sub19 a,&c end
221
- end
222
- end
223
-
224
- def to_limited len=100
225
- LimitedString.new self, len
226
- end
227
-
228
- protected
229
- def split_by_syntax(maxlen, buflen=0)
230
- len, add = maxlen - buflen, nil
231
- [/[^.?!]+\z/, /[^;]+\z/, /[^\n]+/, /\S+\z/, /[^。]+z/, /[^、]+z/].each {|t|
232
- if !(add = self[t]) or add.size <= len
233
- return add
234
- end
235
- }
236
- add
237
- end
238
-
239
- end
240
-
241
- class Indent < String
242
- attr_reader :indent
243
-
244
- def initialize(indent=' ')
245
- @indent = indent
246
- super ''
247
- end
248
-
249
- def +@
250
- self << @indent
251
- end
252
-
253
- def -@
254
- self.chomp! @indent
255
- end
256
-
257
- def i(&block)
258
- +self
259
- res = yield
260
- -self
261
- res
262
- end
263
-
264
- end
265
-
266
- class Regexp
267
-
268
- def | re
269
- Regexp.new(source+'|'+re.source, options | re.options)
270
- end
271
-
272
- def in string
273
- string =~ self
274
- end
275
-
276
- end
@@ -1,106 +0,0 @@
1
- module RMTools
2
-
3
- def format_trace a
4
- bt, calls, i = [], [], 0
5
- # $log.info 'a.size', binding
6
- m = a[0].match(/^(.+):(\d+)(?::in `([^']+)')?$/)
7
- while i < a.size
8
- # $log.info i
9
- m2 = a[i+1] && a[i+1].match(/^(.+):(\d+)(?::in `([^']+)')?$/)
10
- # $log.info 'm', binding
11
- # $log.info 'm2', binding
12
- # $log.info 'm[3] m[1..2]==m2[1..2]', binding if m and m2
13
- # $log.info 'm[1] m[2]', binding if m
14
- # $log.info highlighted_line(*m[1..2]) if m
15
- if m and m[3] and m2 and m[1..2] == m2[1..2]
16
- calls.unshift " <- `#{m[3]}'"
17
- elsif m and m[1] !~ /\.gemspec$/ and line = highlighted_line(*m[1..2])
18
- bt << "#{a[i]}#{calls.join}\n#{line}"
19
- calls = []
20
- else bt << a[i]
21
- end
22
- i += 1
23
- m = m2
24
- end
25
- # $log << Painter.r("FORMAT DONE! #{bt.size} lines formatted")
26
- bt
27
- end
28
-
29
- def highlighted_line_html file, line
30
- if File.file?(file)
31
- " >> <a style=\"color:#0A0; text-decoration: none;\"#{
32
- " href=\"http://#{
33
- defined?(DEBUG_SERVER) ? DEBUG_SERVER : 'localhost:8888'
34
- }/code/#{CGI.escape CGI.escape(file).gsub('.', '%2E')}/#{line}\""
35
- }>#{read_lines(file, line.to_i).chop}</a>"
36
- end
37
- end
38
-
39
- def format_trace_html a
40
- bt, calls, i = [], [], 0
41
- m = a[0].match(/^(.+):(\d+)(?::in `([^']+)')?$/)
42
- while i < a.size
43
- m2 = a[i+1] && a[i+1].match(/^(.+):(\d+)(?::in `([^']+)')?$/)
44
- if m and m[3] and m2 and m[1..2] == m2[1..2]
45
- calls.unshift " <- `#{m[3]}'"
46
- elsif m and m[1] !~ /\.gemspec$/ and line = highlighted_line_html(*m[1..2])
47
- bt << "#{a[i]}#{calls.join}\n#{line}"
48
- calls = []
49
- else bt << a[i]
50
- end
51
- i += 1
52
- m = m2
53
- end
54
- bt
55
- end
56
-
57
- module_function :format_trace, :format_trace_html, :highlighted_line_html
58
- end
59
-
60
- # 1.9 may hung up processing IO while generating traceback
61
- if RUBY_VERSION < '1.9'
62
-
63
- class Class
64
-
65
- def trace_format method
66
- if new.kinda Exception
67
- if method; class_eval(%{
68
- def set_backtrace src
69
- src = #{method} src
70
- set_bt src
71
- end
72
- })
73
- else class_eval(%{
74
- def set_backtrace src
75
- set_bt src
76
- end
77
- })
78
- end
79
- end
80
- end
81
-
82
- end
83
-
84
- class Exception
85
- alias :set_bt :set_backtrace
86
-
87
- # If you set (e.g. in irbrc file) IRB logging and Readline::TEMPLOG:
88
- # module Readline
89
- # TEMPLOG = "path/to/logs/#{Time.now.to_i}.rb"
90
- # alias :orig_readline :readline
91
- # def readline(*args)
92
- # ln = orig_readline(*args)
93
- # RMTools::write TEMPLOG, "#{ln}\n"
94
- # return ln
95
- # end
96
- # end
97
- # it will be possible to get the lines entered in IRB
98
- # else it reads only ordinal require'd files
99
-
100
- trace_format :format_trace
101
-
102
- end
103
-
104
- SystemStackError.trace_format false
105
-
106
- end