eceval 0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eceval.rb +11 -3
  3. data/lib/eceval/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eac2f4e105256977567c95878f0cdef4ad50ff89cb727de06f0abc9eed491de
4
- data.tar.gz: 89526bf8ea8c2d04049d0f25db39d7f1071be0fb787280a34f3c483da64f624f
3
+ metadata.gz: a2776daaaf7e555bdae63232b82115efc512ab1f49260f25e9371d5bd79e8fbe
4
+ data.tar.gz: c90d5b3c010f53f1ce5a9b616b569530fe3db3c9351d29eef2df73ac7c830260
5
5
  SHA512:
6
- metadata.gz: bb608743fec859e597016a9a71b253fbbc4c6826bc56423dff73fe179bfd2aa171b1ae2af47273e40c68dc3f8b66a6f2b301b3131fe3c1fd1a11d2b078382f8b
7
- data.tar.gz: 6cc8a35647e048b2a27667beb302942e456910c992447bdf26a60ae7f7bea2026c4a0d1c7a437f43fe5ccd1a836905e3f7253f6de460e364fb014ff73034b63a
6
+ metadata.gz: addadf832ce7e5f5f92d38203dbc669ecc8884a4a2ede63a6a7627ca65ba32bb0c3ed3a2e691351f0aa10f6d98062668d4d044ba46e55eba8175b884bc624cbd
7
+ data.tar.gz: 2739fa464f360407fae51e66a1242406a8020dfd6fddb31c8d769bf57a07cce0d6139c446ce370a363443cb4e4d23fb6ce0644b0aff1150db1d6c26d840be1b4
@@ -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 + ' ' + format_exception(ex)
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
- "#{ex.class}: #{ex.message}"
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
@@ -1,3 +1,3 @@
1
1
  module Eceval
2
- VERSION = '0.1'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eceval
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Dalling