Class: Bijou::ErrorFormatterText

Inherits:
ErrorFormatter show all
Defined in:
lib/bijou/errorformatter.rb

Instance Attribute Summary

Attributes inherited from ErrorFormatter

#error, #errors, #stack, #title, #warnings

Instance Method Summary collapse

Methods inherited from ErrorFormatter

find_eval_line, format_error, get_file_context, get_source_file_line, #initialize, #set_context

Constructor Details

This class inherits a constructor from Bijou::ErrorFormatter

Instance Method Details

#formatObject



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/bijou/errorformatter.rb', line 204

def format
  result = ''

  # Lead with the error message.
  result << $!.to_s

  #
  # The error description.
  #
  result << "\n\n"
  if @error # This should be $! if set.
    result << error
  end

  # Print a list of errors and warnings.
  errors.each {|m|
    result << m.text + "\n"
  }
  warnings.each {|m|
    result << m.text + "\n"
  }

  if @error_line && @context_lines.length > 0
    # Show where it occurred
    result << "\nContext\n"

    digits = Integer(Math.log10(@error_line + @adjacent_lines) + 1)

    @context_lines.each {|line|
      result << sprintf("%*d: %s\n", digits, line['number'], line['text'])
      if @error_line == line['number']
        if @error_column > 0
          result << sprintf("%*s\n", digits + 1 + @error_column, '^')
        end
      end
    }
  end

  result << "\nStack:\n"
  result << @stack.join("\n")
  
  return result
end