rsql 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rsql +1 -1
- data/lib/rsql.rb +1 -1
- data/lib/rsql/eval_context.rb +43 -8
- data/test/test_eval_context.rb +10 -5
- metadata +4 -4
data/bin/rsql
CHANGED
data/lib/rsql.rb
CHANGED
data/lib/rsql/eval_context.rb
CHANGED
@@ -29,7 +29,8 @@ module RSQL
|
|
29
29
|
#
|
30
30
|
class EvalContext
|
31
31
|
|
32
|
-
Registration = Struct.new(:name, :args, :bangs, :block, :usage,
|
32
|
+
Registration = Struct.new(:name, :args, :bangs, :block, :usage,
|
33
|
+
:desc, :source, :source_fn)
|
33
34
|
|
34
35
|
HEXSTR_LIMIT = 32
|
35
36
|
|
@@ -80,7 +81,17 @@ module RSQL
|
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
83
|
-
def load(fn,
|
84
|
+
def load(fn, opt=nil)
|
85
|
+
# this should only be done after we have established a
|
86
|
+
# mysql connection, so this option allows rsql to load the
|
87
|
+
# init file immediately and then later make the init
|
88
|
+
# registration calls--we set this as an instance variable
|
89
|
+
# to allow for loaded files to call load again and yet
|
90
|
+
# still maintain the skip logic
|
91
|
+
if opt == :skip_init_registrations
|
92
|
+
reset_skipping = @skipping_init_registrations = true
|
93
|
+
end
|
94
|
+
|
84
95
|
ret = Thread.new {
|
85
96
|
begin
|
86
97
|
eval(File.read(fn), binding, fn)
|
@@ -91,12 +102,22 @@ module RSQL
|
|
91
102
|
}.value
|
92
103
|
|
93
104
|
if Exception === ret
|
94
|
-
|
95
|
-
|
105
|
+
if @verbose
|
106
|
+
$stderr.puts("#{ex.class}: #{ex.message}", ex.backtrace)
|
107
|
+
else
|
108
|
+
bt = ret.backtrace.collect{|line| line.start_with?(fn) ? line : nil}.compact
|
109
|
+
$stderr.puts("#{ret.class}: #{ret.message}", bt, '')
|
110
|
+
end
|
111
|
+
ret = false
|
96
112
|
else
|
97
113
|
@loaded_fns << fn unless @loaded_fns.include?(fn)
|
98
|
-
call_init_registrations
|
114
|
+
call_init_registrations unless @skipping_init_registrations
|
115
|
+
ret = true
|
99
116
|
end
|
117
|
+
|
118
|
+
@skipping_init_registrations = false if reset_skipping
|
119
|
+
|
120
|
+
return ret
|
100
121
|
end
|
101
122
|
|
102
123
|
def reload
|
@@ -316,6 +337,10 @@ module RSQL
|
|
316
337
|
return params
|
317
338
|
end
|
318
339
|
|
340
|
+
# Similiar to the MySQL "desc" command, show the content
|
341
|
+
# of nearly any registered recipe including where it was
|
342
|
+
# sourced (e.g. what file:line it came from).
|
343
|
+
#
|
319
344
|
def desc(sym)
|
320
345
|
unless Symbol === sym
|
321
346
|
$stderr.puts("must provide a Symbol--try prefixing it with a colon (:)")
|
@@ -346,6 +371,8 @@ module RSQL
|
|
346
371
|
return
|
347
372
|
end
|
348
373
|
|
374
|
+
reg.source_fn = "#{fn}:#{lineno}"
|
375
|
+
|
349
376
|
File.open(fn) do |f|
|
350
377
|
source = ''
|
351
378
|
i = 0
|
@@ -380,7 +407,7 @@ module RSQL
|
|
380
407
|
end
|
381
408
|
|
382
409
|
if reg.source && !reg.source.empty?
|
383
|
-
puts reg.source
|
410
|
+
puts '', "[#{reg.source_fn}]", '', reg.source
|
384
411
|
else
|
385
412
|
$stderr.puts "unable to locate body for #{sym}"
|
386
413
|
end
|
@@ -401,6 +428,9 @@ module RSQL
|
|
401
428
|
MySQLResults.query(content, self, *args)
|
402
429
|
end
|
403
430
|
|
431
|
+
# Show the most recent queries made to the MySQL server in
|
432
|
+
# this session. Default is to show the last one.
|
433
|
+
#
|
404
434
|
def history(cnt=1)
|
405
435
|
if h = MySQLResults.history(cnt)
|
406
436
|
h.each{|q| puts '', q}
|
@@ -422,6 +452,10 @@ module RSQL
|
|
422
452
|
# sql with variable interpolation.
|
423
453
|
#
|
424
454
|
def register(sym, *args, &block) # :doc:
|
455
|
+
if m = caller.first.match(/^([^:]+:\d+)/)
|
456
|
+
source_fn = m[1]
|
457
|
+
end
|
458
|
+
|
425
459
|
name = usage = sym.to_s
|
426
460
|
|
427
461
|
if Hash === args.last
|
@@ -434,7 +468,7 @@ module RSQL
|
|
434
468
|
desc = '' unless desc
|
435
469
|
|
436
470
|
if block.nil?
|
437
|
-
source = args.pop
|
471
|
+
source = args.pop.strip
|
438
472
|
sql = squeeze!(source.dup)
|
439
473
|
|
440
474
|
argstr = args.join(',')
|
@@ -448,7 +482,8 @@ module RSQL
|
|
448
482
|
usage << params(name, block)
|
449
483
|
end
|
450
484
|
|
451
|
-
@registrations[sym] = Registration.new(name, args, bangs, block, usage,
|
485
|
+
@registrations[sym] = Registration.new(name, args, bangs, block, usage,
|
486
|
+
desc, source, source_fn)
|
452
487
|
end
|
453
488
|
|
454
489
|
# Convert a list of values into a comma-delimited string,
|
data/test/test_eval_context.rb
CHANGED
@@ -27,9 +27,11 @@ class TestEvalContext < Test::Unit::TestCase
|
|
27
27
|
@ctx.load(File.join(File.dirname(__FILE__),'..','example.rsqlrc'))
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def test_reload
|
31
31
|
orig = $stdout
|
32
32
|
$stdout = out = StringIO.new
|
33
|
+
@conn.expects(:query).with(instance_of(String)).returns(nil).times(2)
|
34
|
+
@conn.expects(:affected_rows).returns(0).times(2)
|
33
35
|
@ctx.safe_eval('reload', nil, out)
|
34
36
|
assert_match(/loaded: .+?example.rsqlrc/, out.string)
|
35
37
|
ensure
|
@@ -100,15 +102,18 @@ class TestEvalContext < Test::Unit::TestCase
|
|
100
102
|
out.string = ''
|
101
103
|
val = @ctx.safe_eval('desc :cleanup_example', nil, out)
|
102
104
|
assert_equal('', err.string)
|
103
|
-
|
105
|
+
assert_match(
|
106
|
+
/^\s*\[.+\/example.rsqlrc:\d+\]\s+DROP TEMPORARY TABLE IF EXISTS \#\{@rsql_table\}\s*$/,
|
107
|
+
out.string)
|
104
108
|
|
105
109
|
out.string = ''
|
106
110
|
val = @ctx.safe_eval('desc :to_report', nil, out)
|
107
|
-
lines = out.string.split($/)
|
108
|
-
assert_match(
|
111
|
+
lines = out.string.split($/).select{|l|l.any?}
|
112
|
+
assert_match(/^\[.+\/example.rsqlrc:\d+\]$/, lines[0])
|
113
|
+
assert_match(/^register .+ do$/, lines[1])
|
109
114
|
assert_match(/^\s+puts/, lines[-2])
|
110
115
|
assert_match(/^end$/, lines[-1])
|
111
|
-
assert_equal(
|
116
|
+
assert_equal(13, lines.size)
|
112
117
|
end
|
113
118
|
|
114
119
|
def test_complete
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brad Robel-Forrest
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09
|
18
|
+
date: 2011-10-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: net-ssh
|