eceval 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eceval.rb +14 -3
- data/lib/eceval/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44a1c0931877e7aee230698e6f7dab5f9e60ea6f4f21c0c074a896a275c3f182
|
4
|
+
data.tar.gz: 887e4b402d66da45d62f25e97ab11a0e78f7191921d2908733131a5f6ff368b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c862e12114e5190a69536573a7c8bce78c32d7b3bb74bf1d6d019ade3765d5803f960805377f723d89ac16d3623d4312117ec3c20db562ec58255550351f309d
|
7
|
+
data.tar.gz: 480122c5ebfe4071eccff8b43a6866cb2be040f19d40c700adab213c8a3d2038c6b365537932c205d152e808770f319ffa45e3b55f37beb596a8946dd8362e78
|
data/lib/eceval.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'stringio'
|
2
3
|
|
3
4
|
ECEVAL_MAIN_BINDING = binding
|
4
5
|
|
@@ -6,6 +7,7 @@ module Eceval
|
|
6
7
|
EVAL_MARKER = "#=>"
|
7
8
|
CONTINUATION_MARKER = "#=*"
|
8
9
|
EVAL_EXCEPTION_MARKER = "#=> !!!"
|
10
|
+
STDOUT_MARKER = "# outputs:"
|
9
11
|
BEGIN_CODE_BLOCK = '```ruby'
|
10
12
|
END_CODE_BLOCK = '```'
|
11
13
|
NEW_SCOPE_DIRECTIVE = '# eceval: new_scope'
|
@@ -29,6 +31,7 @@ module Eceval
|
|
29
31
|
@lineno = lineno
|
30
32
|
@lines_consumed = 0
|
31
33
|
@chunk = nil
|
34
|
+
@eval_stdout = StringIO.new
|
32
35
|
end
|
33
36
|
|
34
37
|
def process_line(line)
|
@@ -69,9 +72,6 @@ module Eceval
|
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
|
-
def reset_scope
|
73
|
-
end
|
74
|
-
|
75
75
|
def process_chunk_line(line)
|
76
76
|
@chunk << line
|
77
77
|
|
@@ -83,6 +83,13 @@ module Eceval
|
|
83
83
|
ex = consume_chunk(rescue_exceptions: true)
|
84
84
|
begin_chunk
|
85
85
|
format_exception(line.rstrip, ex)
|
86
|
+
elsif line.rstrip.end_with?(STDOUT_MARKER)
|
87
|
+
consume_chunk
|
88
|
+
begin_chunk
|
89
|
+
output = @eval_stdout.string.chomp
|
90
|
+
@eval_stdout.string = ''
|
91
|
+
|
92
|
+
line + ' ' + output
|
86
93
|
else
|
87
94
|
line
|
88
95
|
end
|
@@ -90,9 +97,11 @@ module Eceval
|
|
90
97
|
|
91
98
|
def consume_chunk(rescue_exceptions: false)
|
92
99
|
old_chunk = @chunk
|
100
|
+
old_stdout = $stdout
|
93
101
|
@chunk = nil
|
94
102
|
|
95
103
|
begin
|
104
|
+
$stdout = @eval_stdout
|
96
105
|
old_chunk.evaluate
|
97
106
|
rescue Exception => ex
|
98
107
|
if rescue_exceptions
|
@@ -100,6 +109,8 @@ module Eceval
|
|
100
109
|
else
|
101
110
|
raise
|
102
111
|
end
|
112
|
+
ensure
|
113
|
+
$stdout = old_stdout
|
103
114
|
end
|
104
115
|
end
|
105
116
|
|
data/lib/eceval/version.rb
CHANGED