Class: Pry::Command::Cat::ExceptionFormatter

Inherits:
AbstractFormatter show all
Includes:
Helpers::Text
Defined in:
lib/pry/commands/cat/exception_formatter.rb

Constant Summary

Constants included from Helpers::Text

Helpers::Text::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Text

#bold, #default, #indent, #no_color, #no_pager, #strip_color, #with_line_numbers

Methods included from Helpers::BaseHelpers

#colorize_code, #find_command, #heading, #highlight, #not_a_real_file?, #safe_send, #silence_warnings, #stagger_output, #use_ansi_codes?

Methods included from Helpers::CommandHelpers

#absolute_index_number, #absolute_index_range, #get_method_or_raise, #internal_binding?, #one_index_number, #one_index_range, #one_index_range_or_number, #restrict_to_lines, #set_file_and_dir_locals, #temp_file, #unindent

Methods included from Helpers::OptionsHelpers

method_object, method_options

Constructor Details

#initialize(exception, pry_instance, opts) ⇒ ExceptionFormatter

Returns a new instance of ExceptionFormatter.



12
13
14
15
16
# File 'lib/pry/commands/cat/exception_formatter.rb', line 12

def initialize(exception, pry_instance, opts)
  @ex = exception
  @opts = opts
  @pry_instance = pry_instance
end

Instance Attribute Details

#exObject (readonly)

Returns the value of attribute ex.



7
8
9
# File 'lib/pry/commands/cat/exception_formatter.rb', line 7

def ex
  @ex
end

#optsObject (readonly)

Returns the value of attribute opts.



8
9
10
# File 'lib/pry/commands/cat/exception_formatter.rb', line 8

def opts
  @opts
end

#pry_instanceObject (readonly)

Returns the value of attribute pry_instance.



9
10
11
# File 'lib/pry/commands/cat/exception_formatter.rb', line 9

def pry_instance
  @pry_instance
end

Instance Method Details

#formatObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pry/commands/cat/exception_formatter.rb', line 18

def format
  check_for_errors
  set_file_and_dir_locals(
    backtrace_file, pry_instance, pry_instance.current_context
  )
  code = decorate(
    Pry::Code.from_file(backtrace_file)
      .between(*start_and_end_line_for_code_window)
      .with_marker(backtrace_line)
  )
  "#{header}#{code}"
end