eceval 0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/eceval.rb +11 -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: a2776daaaf7e555bdae63232b82115efc512ab1f49260f25e9371d5bd79e8fbe
|
4
|
+
data.tar.gz: c90d5b3c010f53f1ce5a9b616b569530fe3db3c9351d29eef2df73ac7c830260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: addadf832ce7e5f5f92d38203dbc669ecc8884a4a2ede63a6a7627ca65ba32bb0c3ed3a2e691351f0aa10f6d98062668d4d044ba46e55eba8175b884bc624cbd
|
7
|
+
data.tar.gz: 2739fa464f360407fae51e66a1242406a8020dfd6fddb31c8d769bf57a07cce0d6139c446ce370a363443cb4e4d23fb6ce0644b0aff1150db1d6c26d840be1b4
|
data/lib/eceval.rb
CHANGED
@@ -4,6 +4,7 @@ ECEVAL_MAIN_BINDING = binding
|
|
4
4
|
|
5
5
|
module Eceval
|
6
6
|
EVAL_MARKER = "#=>"
|
7
|
+
CONTINUATION_MARKER = "#=*"
|
7
8
|
EVAL_EXCEPTION_MARKER = "#=> !!!"
|
8
9
|
BEGIN_CODE_BLOCK = '```ruby'
|
9
10
|
END_CODE_BLOCK = '```'
|
@@ -81,7 +82,7 @@ module Eceval
|
|
81
82
|
elsif line.rstrip.end_with?(EVAL_EXCEPTION_MARKER)
|
82
83
|
ex = consume_chunk(rescue_exceptions: true)
|
83
84
|
begin_chunk
|
84
|
-
line.rstrip
|
85
|
+
format_exception(line.rstrip, ex)
|
85
86
|
else
|
86
87
|
line
|
87
88
|
end
|
@@ -102,14 +103,21 @@ module Eceval
|
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
105
|
-
def format_exception(ex)
|
106
|
+
def format_exception(line, ex)
|
106
107
|
unless ex.is_a?(Exception)
|
107
108
|
raise NoExceptionRaised, "Expected an exception at #{current_pos}" \
|
108
109
|
" but none was raised. Instead, the code evaluated to: " +
|
109
110
|
ex.inspect
|
110
111
|
end
|
111
112
|
|
112
|
-
|
113
|
+
# for multiline exception messages, indent them to line up with the first line
|
114
|
+
indentation = CONTINUATION_MARKER + ' '*(line.length - CONTINUATION_MARKER.length + 1)
|
115
|
+
ex_message = ex.message
|
116
|
+
.lines
|
117
|
+
.map(&:chomp)
|
118
|
+
.join("\n" + indentation)
|
119
|
+
|
120
|
+
"#{line} #{ex.class}: #{ex_message}"
|
113
121
|
end
|
114
122
|
|
115
123
|
def current_pos
|
data/lib/eceval/version.rb
CHANGED