pry-command_result 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,31 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
|
3
3
|
module Kernel
|
4
|
-
def command_result(command)
|
5
|
-
|
4
|
+
def command_result(command, target = binding)
|
5
|
+
is_command = Pry.commands.to_a.map(&:first).any? do |cmd|
|
6
|
+
case cmd
|
7
|
+
when Regexp
|
8
|
+
cmd =~ command.split(' ').first
|
9
|
+
when String
|
10
|
+
cmd == command.split(' ').first
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
pager = Pry.config.pager
|
7
15
|
color = Pry.config.color
|
8
16
|
Pry.config.pager = false
|
9
17
|
Pry.config.color = false
|
10
|
-
|
11
|
-
|
18
|
+
|
19
|
+
if is_command
|
20
|
+
output = StringIO.new
|
21
|
+
Pry.run_command(command, output: output, show_output: true)
|
22
|
+
output.string
|
23
|
+
else
|
24
|
+
eval(command, target)
|
25
|
+
end
|
12
26
|
ensure
|
13
27
|
Pry.config.color = color
|
14
28
|
Pry.config.pager = pager
|
15
|
-
output.close
|
29
|
+
output.close if output.respond_to? :close
|
16
30
|
end
|
17
31
|
end
|