utils 0.0.39 → 0.0.40
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/TODO +1 -2
- data/VERSION +1 -1
- data/bin/chroot-libs +8 -4
- data/bin/probe +31 -26
- data/lib/utils/config/config_file.rb +7 -5
- data/lib/utils/config/irbrc +1 -491
- data/lib/utils/config/vim/autoload/rails.vim +16 -16
- data/lib/utils/editor.rb +17 -5
- data/lib/utils/file_xt.rb +3 -6
- data/lib/utils/find.rb +132 -28
- data/lib/utils/finder.rb +5 -5
- data/lib/utils/grepper.rb +7 -4
- data/lib/utils/irb.rb +507 -0
- data/lib/utils/version.rb +1 -1
- data/utils.gemspec +11 -11
- metadata +46 -15
data/Rakefile
CHANGED
@@ -15,9 +15,9 @@ GemHadar do
|
|
15
15
|
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', '.AppleDouble'
|
16
16
|
readme 'README.rdoc'
|
17
17
|
|
18
|
-
dependency 'tins', '~>0.3'
|
18
|
+
dependency 'tins', '~>0.3.12'
|
19
19
|
dependency 'term-ansicolor', '~>1.0'
|
20
|
-
dependency 'dslkit', '~>0.2'
|
20
|
+
dependency 'dslkit', '~>0.2.10'
|
21
21
|
dependency 'pry-editline'
|
22
22
|
|
23
23
|
install_library do
|
data/TODO
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
-
|
2
|
-
- make -I option take a list (comma <- or spaces seperated?)
|
1
|
+
- improve backup mechanism for new configuration, interactivity?
|
3
2
|
|
4
3
|
CHECK
|
5
4
|
- When finding many places in the same file only jump to the first occurence if
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.40
|
data/bin/chroot-libs
CHANGED
@@ -9,10 +9,14 @@ dir = ARGV.shift or fail msg
|
|
9
9
|
dir = File.expand_path dir
|
10
10
|
mkdir_p dir
|
11
11
|
|
12
|
-
executable
|
12
|
+
unless executable.start_with? '/'
|
13
|
+
executable = `which #{executable}`.chomp
|
14
|
+
end
|
13
15
|
libs = `ldd #{executable}`.gsub(/^(?:.*?\s+=>\s+|\s+)(.*?)\(.*/, '\1').grep(/\S/).map { |x| x.strip }
|
14
16
|
libs.concat ARGV
|
15
|
-
cd dir
|
16
|
-
|
17
|
-
|
17
|
+
cd dir do
|
18
|
+
cp executable, File.basename(executable)
|
19
|
+
for l in libs
|
20
|
+
cp l, File.basename(l)
|
21
|
+
end
|
18
22
|
end
|
data/bin/probe
CHANGED
@@ -9,7 +9,7 @@ include Utils
|
|
9
9
|
|
10
10
|
def usage
|
11
11
|
puts <<-EOT
|
12
|
-
Usage: #{File.basename($0)} [OPTS] FILENAME[:LINENO]
|
12
|
+
Usage: #{File.basename($0)} [OPTS] FILENAME[:LINENO] [FILENAME]
|
13
13
|
|
14
14
|
Options are
|
15
15
|
|
@@ -24,7 +24,7 @@ end
|
|
24
24
|
|
25
25
|
def cmd(*args)
|
26
26
|
puts args * ' '
|
27
|
-
|
27
|
+
system(*args)
|
28
28
|
end
|
29
29
|
|
30
30
|
$config = Utils::Config::ConfigFile.new
|
@@ -32,38 +32,43 @@ $config.parse_config_file File.expand_path('~/.utilsrc')
|
|
32
32
|
testrunner_args = []
|
33
33
|
if i = ARGV.index('--')
|
34
34
|
testrunner_args.concat ARGV[(i + 1)..-1]
|
35
|
-
|
35
|
+
args = ARGV[0...i]
|
36
|
+
else
|
37
|
+
args = ARGV.dup
|
36
38
|
end
|
37
|
-
$opt = go 't:n:h
|
38
|
-
|
39
|
+
$opt = go 't:n:h', args
|
40
|
+
args.empty? and fail "require filename or filename:linenumber as arguments"
|
39
41
|
$opt['h'] and usage
|
42
|
+
|
43
|
+
puts "Running tests in #{args.inspect}"
|
44
|
+
|
40
45
|
case ($opt['t'] || $config.probe.test_framework).to_sym
|
41
46
|
when :rspec
|
42
|
-
if
|
43
|
-
cmd "rspec", '-I', $config.probe.include_dirs_argument, '-l',
|
44
|
-
|
45
|
-
filename, line_number = $1, $2
|
46
|
-
puts "Running test at #{filename}:#{line_number}"
|
47
|
-
cmd "rspec", '-I', $config.probe.include_dirs_argument, '-l', line_number, filename, *testrunner_args
|
47
|
+
if linenumber = $opt['n']
|
48
|
+
cmd "rspec", '-I', $config.probe.include_dirs_argument, '-l', linenumber,
|
49
|
+
*args, *testrunner_args
|
48
50
|
else
|
49
|
-
|
50
|
-
cmd "rspec", '-I', $config.probe.include_dirs_argument, filename, *testrunner_args
|
51
|
+
cmd "rspec", '-I', $config.probe.include_dirs_argument, *args, *testrunner_args
|
51
52
|
end
|
52
53
|
when :'test-unit'
|
53
54
|
if testname = $opt['n']
|
54
|
-
cmd "testrb", '-I', $config.probe.include_dirs_argument, '-n', testname,
|
55
|
-
|
56
|
-
filename, line_number = $1, $2
|
57
|
-
lf = Tins::LinesFile.for_filename filename, line_number.to_i
|
58
|
-
if testname = lf.match_backward(/def\s+(\S+?)(?:\(|\s*$)/).full?(:first)
|
59
|
-
puts "Running test #{testname.inspect} at #{filename}:#{lf.line_number}"
|
60
|
-
cmd "testrb", '-I', $config.probe.include_dirs_argument, '-n', testname, filename, *testrunner_args
|
61
|
-
else
|
62
|
-
warn "no test found before line #{line_number}"
|
63
|
-
exit 1
|
64
|
-
end
|
55
|
+
cmd "testrb", '-I', $config.probe.include_dirs_argument, '-n', testname,
|
56
|
+
*args, *testrunner_args
|
65
57
|
else
|
66
|
-
|
67
|
-
|
58
|
+
for filename in args
|
59
|
+
sl = filename.source_location
|
60
|
+
if sl.linenumber
|
61
|
+
lf = Tins::LinesFile.for_filename(*sl)
|
62
|
+
if testname = lf.match_backward(/def\s+(\S+?)(?:\(|\s*$)/).full?(:first)
|
63
|
+
cmd "testrb", '-I', $config.probe.include_dirs_argument,
|
64
|
+
'-n', testname, sl.filename, *testrunner_args
|
65
|
+
else
|
66
|
+
warn "no test found before line #{sl.linenumber}"
|
67
|
+
end
|
68
|
+
else
|
69
|
+
cmd "testrb", '-I', $config.probe.include_dirs_argument, sl.filename,
|
70
|
+
*testrunner_args
|
71
|
+
end
|
72
|
+
end
|
68
73
|
end
|
69
74
|
end
|
@@ -15,7 +15,8 @@ class Utils::Config::ConfigFile
|
|
15
15
|
end
|
16
16
|
self
|
17
17
|
rescue SystemCallError => e
|
18
|
-
$DEBUG and warn "Couldn't read config file
|
18
|
+
$DEBUG and warn "Couldn't read config file "\
|
19
|
+
"#{config_file_name.inspect}: #{e.class} #{e}"
|
19
20
|
return nil
|
20
21
|
end
|
21
22
|
|
@@ -67,8 +68,9 @@ class Utils::Config::ConfigFile
|
|
67
68
|
def initialize(&block)
|
68
69
|
super
|
69
70
|
test_frameworks_allowed = [ :'test-unit', :rspec ]
|
70
|
-
test_frameworks_allowed.include?(test_framework) or
|
71
|
-
|
71
|
+
test_frameworks_allowed.include?(test_framework) or
|
72
|
+
raise ConfigFileError,
|
73
|
+
"test_framework has to be in #{test_frameworks_allowed.inspect}"
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
@@ -81,11 +83,11 @@ class Utils::Config::ConfigFile
|
|
81
83
|
|
82
84
|
class FileFinder < BlockConfig
|
83
85
|
def prune?(basename)
|
84
|
-
Array(prune_dirs).any? { |pd| pd.match(basename) }
|
86
|
+
Array(prune_dirs).any? { |pd| pd.match(basename.to_s) }
|
85
87
|
end
|
86
88
|
|
87
89
|
def skip?(basename)
|
88
|
-
Array(skip_files).any? { |sf| sf.match(basename) }
|
90
|
+
Array(skip_files).any? { |sf| sf.match(basename.to_s) }
|
89
91
|
end
|
90
92
|
end
|
91
93
|
|
data/lib/utils/config/irbrc
CHANGED
@@ -1,493 +1,3 @@
|
|
1
1
|
# vim: set filetype=ruby et sw=2 ts=2:
|
2
2
|
|
3
|
-
|
4
|
-
require 'irb/completion'
|
5
|
-
require 'enumerator'
|
6
|
-
require 'pp'
|
7
|
-
require 'fileutils'
|
8
|
-
require 'find'
|
9
|
-
if Readline.respond_to?(:point) && Readline.respond_to?(:line_buffer)
|
10
|
-
require 'pry-editline'
|
11
|
-
end
|
12
|
-
include FileUtils
|
13
|
-
begin
|
14
|
-
require 'ap'
|
15
|
-
rescue LoadError
|
16
|
-
end
|
17
|
-
require 'utils'
|
18
|
-
$editor = Utils::Editor.new
|
19
|
-
|
20
|
-
$pager = ENV['PAGER'] || 'less -r'
|
21
|
-
|
22
|
-
class Symbol
|
23
|
-
def to_proc
|
24
|
-
Proc.new do |obj, *args|
|
25
|
-
obj.__send__(self, *args)
|
26
|
-
end
|
27
|
-
end unless method_defined?(:to_proc)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Start _ri_ for +pattern+. If +pattern+ is not string like, call it with
|
31
|
-
# pattern.class.name as argument.
|
32
|
-
def ri(*patterns)
|
33
|
-
patterns.map! { |p| p.respond_to?(:to_str) ? p.to_str : p.class.name }
|
34
|
-
system "ri #{patterns.map { |p| "'#{p}'" } * ' '} | #{$pager}"
|
35
|
-
end
|
36
|
-
|
37
|
-
class Module
|
38
|
-
# Start +ri+ for +module#pattern+, trying to find a method matching +pattern+
|
39
|
-
# for all modules in the ancestors chain of this module.
|
40
|
-
def ri(pattern = nil)
|
41
|
-
if pattern
|
42
|
-
pattern = pattern.to_sym.to_s if pattern.respond_to? :to_sym
|
43
|
-
ancestors.each do |a|
|
44
|
-
if method = a.instance_methods(false).find { |m| pattern === m }
|
45
|
-
a = Object if a == Kernel # ri seems to be confused
|
46
|
-
system "ri #{a}##{method} | #{$pager}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
else
|
50
|
-
system "ri #{self} | #{$pager}"
|
51
|
-
end
|
52
|
-
return
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Restart this irb.
|
57
|
-
def irb_restart
|
58
|
-
exec $0
|
59
|
-
end
|
60
|
-
|
61
|
-
# Return all instance methods of obj's class.
|
62
|
-
def irb_all_class_instance_methods(obj)
|
63
|
-
methods = obj.class.instance_methods
|
64
|
-
irb_wrap_methods obj, methods
|
65
|
-
end
|
66
|
-
|
67
|
-
# Return instance methods of obj's class without the inherited/mixed in
|
68
|
-
# methods.
|
69
|
-
def irb_class_instance_methods(obj)
|
70
|
-
methods = obj.class.instance_methods(false)
|
71
|
-
irb_wrap_methods obj, methods
|
72
|
-
end
|
73
|
-
|
74
|
-
# Return all instance methods defined in module modul.
|
75
|
-
def irb_all_instance_methods(modul)
|
76
|
-
methods = modul.instance_methods
|
77
|
-
irb_wrap_methods modul, methods, true
|
78
|
-
end
|
79
|
-
|
80
|
-
# Return instance methods defined in module modul without the inherited/mixed
|
81
|
-
# in methods.
|
82
|
-
def irb_instance_methods(modul)
|
83
|
-
methods = modul.instance_methods(false)
|
84
|
-
irb_wrap_methods modul, methods, true
|
85
|
-
end
|
86
|
-
|
87
|
-
# Return all methods of obj (including obj's eigenmethods.)
|
88
|
-
def irb_all_methods(obj)
|
89
|
-
methods = obj.methods
|
90
|
-
irb_wrap_methods obj, methods
|
91
|
-
end
|
92
|
-
|
93
|
-
# Return instance methods of obj's class without the inherited/mixed in
|
94
|
-
# methods, but including obj's eigenmethods.
|
95
|
-
def irb_methods(obj)
|
96
|
-
methods = obj.class.ancestors[1..-1].inject(obj.methods) do |all, a|
|
97
|
-
all -= a.instance_methods
|
98
|
-
end
|
99
|
-
irb_wrap_methods obj, methods
|
100
|
-
end
|
101
|
-
|
102
|
-
# Return all eigen methods of obj.
|
103
|
-
def irb_eigen_methods(obj)
|
104
|
-
irb_wrap_methods obj, obj.methods(false)
|
105
|
-
end
|
106
|
-
|
107
|
-
def irb_wrap_methods(obj, methods, modul = false)
|
108
|
-
methods.map do |name|
|
109
|
-
MethodWrapper.new(obj, name, modul)
|
110
|
-
end.sort!
|
111
|
-
end
|
112
|
-
|
113
|
-
class WrapperBase
|
114
|
-
include Comparable
|
115
|
-
|
116
|
-
def initialize(name)
|
117
|
-
@name =
|
118
|
-
case
|
119
|
-
when name.respond_to?(:to_str)
|
120
|
-
name.to_str
|
121
|
-
when name.respond_to?(:to_sym)
|
122
|
-
name.to_sym.to_s
|
123
|
-
else
|
124
|
-
name.to_s
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
attr_reader :name
|
129
|
-
|
130
|
-
attr_reader :description
|
131
|
-
|
132
|
-
alias to_str name
|
133
|
-
|
134
|
-
alias inspect description
|
135
|
-
|
136
|
-
alias to_s description
|
137
|
-
|
138
|
-
def ==(name)
|
139
|
-
@name = name
|
140
|
-
end
|
141
|
-
|
142
|
-
alias eql? ==
|
143
|
-
|
144
|
-
def hash
|
145
|
-
@name.hash
|
146
|
-
end
|
147
|
-
|
148
|
-
def <=>(other)
|
149
|
-
@name <=> other.name
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
class MethodWrapper < WrapperBase
|
154
|
-
def initialize(obj, name, modul)
|
155
|
-
super(name)
|
156
|
-
if modul
|
157
|
-
@arity = obj.instance_method(name).arity
|
158
|
-
else
|
159
|
-
@arity = obj.method(name).arity
|
160
|
-
end
|
161
|
-
@description = "#@name(#@arity)"
|
162
|
-
end
|
163
|
-
|
164
|
-
attr_reader :arity
|
165
|
-
end
|
166
|
-
|
167
|
-
class ConstantWrapper < WrapperBase
|
168
|
-
def initialize(obj, name)
|
169
|
-
super(name)
|
170
|
-
@klass = obj.class
|
171
|
-
@description = "#@name:#@klass"
|
172
|
-
end
|
173
|
-
|
174
|
-
attr_reader :klass
|
175
|
-
end
|
176
|
-
|
177
|
-
# Return all the constants defined in +modul+.
|
178
|
-
def irb_constants(modul)
|
179
|
-
modul.constants.map { |c| ConstantWrapper.new(modul.const_get(c), c) }.sort
|
180
|
-
end
|
181
|
-
|
182
|
-
# Return all the subclasses of +klass+. TODO implement subclasses w/out rails
|
183
|
-
def irb_subclasses(klass)
|
184
|
-
klass.subclasses.map { |c| ConstantWrapper.new(eval(c), c) }.sort
|
185
|
-
end
|
186
|
-
|
187
|
-
unless Object.const_defined?(:Infinity)
|
188
|
-
Infinity = 1.0 / 0 # I like to define the infinite.
|
189
|
-
end
|
190
|
-
|
191
|
-
# Output all kinds of information about +obj+. If detailed is given output
|
192
|
-
# details about the methods (+ arity) in inheritance chain of +obj+ as well.
|
193
|
-
# * detailed as 0 output instance methods only of part 0 (the first) of the
|
194
|
-
# chain.
|
195
|
-
# * detailed as 1..2 output instance methods of +obj+ inherited from parts 1
|
196
|
-
# and 2 of the the chain.
|
197
|
-
def irb_info(obj, detailed = nil)
|
198
|
-
if Module === obj
|
199
|
-
modul = obj
|
200
|
-
klassp = Class === modul
|
201
|
-
if klassp
|
202
|
-
obj = modul.allocate
|
203
|
-
end
|
204
|
-
else
|
205
|
-
modul = obj.class
|
206
|
-
end
|
207
|
-
inspected = obj.inspect
|
208
|
-
puts "obj = #{inspected.size > 40 ? inspected[0, 40] + '...' : inspected} is of class #{obj.class}."
|
209
|
-
am = irb_all_methods(obj).size
|
210
|
-
ms = irb_methods(obj).size
|
211
|
-
ems = irb_eigen_methods(obj).size
|
212
|
-
puts "obj: #{am} methods, #{ms} only local#{ems > 0 ? " (#{ems} eigenmethods),": ','} #{am - ms} inherited/mixed in."
|
213
|
-
acim = irb_all_class_instance_methods(obj).size
|
214
|
-
cim = irb_class_instance_methods(obj).size
|
215
|
-
puts "obj: #{acim} instance methods, #{cim} local, #{acim - cim} only inherited/mixed in."
|
216
|
-
if klassp
|
217
|
-
s = modul.superclass
|
218
|
-
puts "Superclass of #{modul}: #{s}"
|
219
|
-
end
|
220
|
-
a = []
|
221
|
-
ec = true
|
222
|
-
begin
|
223
|
-
a << (class << obj; self; end)
|
224
|
-
rescue TypeError
|
225
|
-
ec = false
|
226
|
-
end
|
227
|
-
a.concat modul.ancestors
|
228
|
-
if ec
|
229
|
-
puts "Ancestors of #{modul}: (#{a[0]},) #{a[1..-1].map { |k| "#{k}#{k == s ? '*' : ''}" } * ', '}"
|
230
|
-
else
|
231
|
-
puts "Ancestors of #{modul}: #{a[0..-1].map { |k| "#{k}#{k == s ? '*' : ''}" } * ', '}"
|
232
|
-
end
|
233
|
-
if Class === modul and detailed
|
234
|
-
if detailed.respond_to? :to_int
|
235
|
-
detailed = detailed..detailed
|
236
|
-
end
|
237
|
-
detailed.each do |i|
|
238
|
-
break if i >= a.size
|
239
|
-
k = a[i]
|
240
|
-
puts "#{k}:"
|
241
|
-
puts irb_wrap_methods(obj, k.instance_methods(false)).sort
|
242
|
-
end
|
243
|
-
end
|
244
|
-
nil
|
245
|
-
end
|
246
|
-
|
247
|
-
# Output *all* the irb_info about +obj+. You may need to buy a bigger screen for
|
248
|
-
# this or use:
|
249
|
-
# less { irb_fullinfo object }
|
250
|
-
def irb_fullinfo(obj)
|
251
|
-
irb_info obj, 0..Infinity
|
252
|
-
end
|
253
|
-
|
254
|
-
def capture_output(with_stderr = false)
|
255
|
-
return "missing block" unless block_given?
|
256
|
-
require 'tempfile'
|
257
|
-
begin
|
258
|
-
old_stdout, $stdout = $stdout, Tempfile.new('irb')
|
259
|
-
if with_stderr
|
260
|
-
old_stderr, $stderr = $stderr, $stdout
|
261
|
-
end
|
262
|
-
yield
|
263
|
-
ensure
|
264
|
-
$stdout, temp = old_stdout, $stdout
|
265
|
-
with_stderr and $stderr = old_stderr
|
266
|
-
end
|
267
|
-
temp.rewind
|
268
|
-
temp.read
|
269
|
-
end
|
270
|
-
|
271
|
-
# Use pager on the output of the commands given in the block.
|
272
|
-
def less(with_stderr = false, &block)
|
273
|
-
IO.popen($pager, 'w') do |f|
|
274
|
-
f.write capture_output(with_stderr, &block)
|
275
|
-
f.close_write
|
276
|
-
end
|
277
|
-
nil
|
278
|
-
end
|
279
|
-
|
280
|
-
class String
|
281
|
-
# Pipe this string into +cmd+.
|
282
|
-
def |(cmd)
|
283
|
-
IO.popen(cmd, 'w+') do |f|
|
284
|
-
f.write self
|
285
|
-
f.close_write
|
286
|
-
return f.read
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
# Write this string into file +filename+.
|
291
|
-
def >>(filename)
|
292
|
-
irb_write(filename, self)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
def irb_time
|
297
|
-
s = Time.now
|
298
|
-
yield
|
299
|
-
d = Time.now - s
|
300
|
-
warn "Took %.3fs seconds." % d
|
301
|
-
d
|
302
|
-
end
|
303
|
-
|
304
|
-
def irb_time_tap
|
305
|
-
r = nil
|
306
|
-
irb_time { r = yield }
|
307
|
-
r
|
308
|
-
end
|
309
|
-
|
310
|
-
def irb_time_watch(duration = 1)
|
311
|
-
start = Time.now
|
312
|
-
pre = nil
|
313
|
-
loop do
|
314
|
-
cur = [ yield ].flatten
|
315
|
-
unless pre
|
316
|
-
pre = cur.map(&:to_f)
|
317
|
-
cur = [ yield ].flatten
|
318
|
-
end
|
319
|
-
expired = Time.now - start
|
320
|
-
diffs = cur.zip(pre).map { |c, p| c - p }
|
321
|
-
rates = diffs.map { |d| d / duration }
|
322
|
-
warn "#{expired} #{cur.zip(rates, diffs).map(&:inspect) * ' '} # / per sec."
|
323
|
-
pre = cur.map(&:to_f)
|
324
|
-
sleep duration
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
def irb_write(filename, text = nil)
|
329
|
-
if block_given?
|
330
|
-
text = yield
|
331
|
-
else
|
332
|
-
text or raise "need a text as argument or as a block return value"
|
333
|
-
end
|
334
|
-
open(filename, 'wb') { |f| f.write text }
|
335
|
-
end
|
336
|
-
|
337
|
-
def irb_read(filename, chunk_size = 8_192)
|
338
|
-
if block_given?
|
339
|
-
File.open(filename) do |file|
|
340
|
-
until file.eof?
|
341
|
-
yield file.read(chunk_size)
|
342
|
-
end
|
343
|
-
end
|
344
|
-
else
|
345
|
-
IO.read filename
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
def irb_load!(*files)
|
350
|
-
files = files.map { |f| f.gsub(/(\.rb)?\Z/, '.rb') }
|
351
|
-
loaded = {}
|
352
|
-
for file in files
|
353
|
-
catch :found do
|
354
|
-
Find.find('.') do |f|
|
355
|
-
File.directory?(f) and next
|
356
|
-
md5_f = Utils::MD5.md5(f)
|
357
|
-
if f.end_with?(file) and !loaded[md5_f]
|
358
|
-
Kernel.load f
|
359
|
-
loaded[md5_f] = true
|
360
|
-
STDERR.puts "Loaded '#{f}'."
|
361
|
-
end
|
362
|
-
end
|
363
|
-
Find.find('.') do |f|
|
364
|
-
File.directory?(f) and next
|
365
|
-
md5_f = Utils::MD5.md5(f)
|
366
|
-
if f.end_with?(file) and !loaded[md5_f]
|
367
|
-
Kernel.load f
|
368
|
-
loaded[md5_f] = true
|
369
|
-
STDERR.puts "Loaded '#{f}'."
|
370
|
-
end
|
371
|
-
end
|
372
|
-
end
|
373
|
-
end
|
374
|
-
nil
|
375
|
-
end
|
376
|
-
|
377
|
-
def irb_edit(*files)
|
378
|
-
$editor.edit(*files)
|
379
|
-
end
|
380
|
-
|
381
|
-
class Regexp
|
382
|
-
# Show the match of this Regexp on the +string+.
|
383
|
-
def show_match(string)
|
384
|
-
string =~ self ? "#{$`}<<#{$&}>>#{$'}" : "no match"
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
if IRB.conf[:PROMPT]
|
389
|
-
IRB.conf[:PROMPT][:CUSTOM] = {
|
390
|
-
:PROMPT_I => ">> ",
|
391
|
-
:PROMPT_N => ">> ",
|
392
|
-
:PROMPT_S => "%l> ",
|
393
|
-
:PROMPT_C => "+> ",
|
394
|
-
:RETURN => " # => %s\n"
|
395
|
-
}
|
396
|
-
IRB.conf[:PROMPT_MODE] = :CUSTOM
|
397
|
-
end
|
398
|
-
|
399
|
-
module ::IRB
|
400
|
-
class Context
|
401
|
-
def init_save_history
|
402
|
-
unless (class<<@io;self;end).include?(HistorySavingAbility)
|
403
|
-
@io.extend(HistorySavingAbility)
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
def save_history
|
408
|
-
IRB.conf[:SAVE_HISTORY]
|
409
|
-
end
|
410
|
-
|
411
|
-
def save_history=(val)
|
412
|
-
IRB.conf[:SAVE_HISTORY] = val
|
413
|
-
if val
|
414
|
-
main_context = IRB.conf[:MAIN_CONTEXT]
|
415
|
-
main_context = self unless main_context
|
416
|
-
main_context.init_save_history
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
def history_file
|
421
|
-
IRB.conf[:HISTORY_FILE]
|
422
|
-
end
|
423
|
-
|
424
|
-
def history_file=(hist)
|
425
|
-
IRB.conf[:HISTORY_FILE] = hist
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
module HistorySavingAbility
|
430
|
-
include Readline
|
431
|
-
|
432
|
-
def HistorySavingAbility.create_finalizer
|
433
|
-
at_exit do
|
434
|
-
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
|
435
|
-
if hf = IRB.conf[:HISTORY_FILE]
|
436
|
-
file = File.expand_path(hf)
|
437
|
-
end
|
438
|
-
file = IRB.rc_file("_history") unless file
|
439
|
-
open(file, 'w' ) do |f|
|
440
|
-
hist = HISTORY.to_a
|
441
|
-
f.puts(hist[-num..-1] || hist)
|
442
|
-
end
|
443
|
-
end
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
def HistorySavingAbility.extended(obj)
|
448
|
-
HistorySavingAbility.create_finalizer
|
449
|
-
obj.load_history
|
450
|
-
obj
|
451
|
-
end
|
452
|
-
|
453
|
-
def load_history
|
454
|
-
hist = IRB.conf[:HISTORY_FILE]
|
455
|
-
hist = IRB.rc_file("_history") unless hist
|
456
|
-
if File.exist?(hist)
|
457
|
-
open(hist) do |f|
|
458
|
-
f.each {|l| HISTORY << l.chomp}
|
459
|
-
end
|
460
|
-
end
|
461
|
-
end
|
462
|
-
end
|
463
|
-
end
|
464
|
-
IRB.conf[:SAVE_HISTORY] = 1000
|
465
|
-
|
466
|
-
# List contents of directory
|
467
|
-
def ls(*args)
|
468
|
-
puts `ls #{args.map { |x| "'#{x}'" } * ' '}`
|
469
|
-
end
|
470
|
-
|
471
|
-
if defined?(ActiveRecord::Base)
|
472
|
-
$logger = Logger.new(STDERR)
|
473
|
-
def irb_toggle_logging
|
474
|
-
require 'logger'
|
475
|
-
if ActiveRecord::Base.logger != $logger
|
476
|
-
$old_logger = ActiveRecord::Base.logger
|
477
|
-
ActiveRecord::Base.logger = $logger
|
478
|
-
true
|
479
|
-
else
|
480
|
-
ActiveRecord::Base.logger = $old_logger
|
481
|
-
false
|
482
|
-
end
|
483
|
-
end
|
484
|
-
|
485
|
-
end
|
486
|
-
|
487
|
-
if defined?(ActiveRecord::Relation)
|
488
|
-
class ActiveRecord::Relation
|
489
|
-
def explain
|
490
|
-
connection.select_all("EXPLAIN #{to_sql}")
|
491
|
-
end
|
492
|
-
end
|
493
|
-
end
|
3
|
+
require 'utils/irb'
|