Class: PryMoves::Backtrace

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-moves/backtrace.rb

Constant Summary collapse

FILTERS =
%w[/gems/ /rubygems/ /bin/ /lib/ruby/]
@@backtrace =
nil

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pry) ⇒ Backtrace

Returns a new instance of Backtrace.



29
30
31
32
# File 'lib/pry-moves/backtrace.rb', line 29

def initialize(pry)
  @pry = pry
  @builder = PryMoves::BacktraceBuilder.new frame_manager
end

Class Attribute Details

.trim_pathObject

Returns the value of attribute trim_path.



10
11
12
# File 'lib/pry-moves/backtrace.rb', line 10

def trim_path
  @trim_path
end

Class Method Details

.filterObject



12
13
14
# File 'lib/pry-moves/backtrace.rb', line 12

def filter
  @filter ||= Regexp.new FILTERS.join("|")
end

.filter=(f) ⇒ Object



15
# File 'lib/pry-moves/backtrace.rb', line 15

def filter=(f); @filter = f; end

.format(&block) ⇒ Object



17
18
19
# File 'lib/pry-moves/backtrace.rb', line 17

def format(&block)
  @formatter = block
end

.formatterObject



21
22
23
24
25
# File 'lib/pry-moves/backtrace.rb', line 21

def formatter
  @formatter || lambda do |line|
    # not used
  end
end

Instance Method Details

#run_command(param, param2) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pry-moves/backtrace.rb', line 34

def run_command(param, param2)
  if param == 'save' || param == 'diff' && @@backtrace.nil?
    @@hard_saved = param == 'save'
    @builder.filter = 'hidden'
    @builder.lines_numbers = false
    @@backtrace = @builder.build_backtrace
    @pry.output.puts "💾 Backtrace saved (#{@@backtrace.count} lines)"
  elsif param == 'diff'
    @builder.filter = 'hidden'
    @builder.lines_numbers = false
    diff
    @@backtrace = nil unless @@hard_saved
  elsif param and (match = param.match /^::(\w*)/)
    @builder.colorize = true
    @pry.output.puts @builder.objects_of_class match[1]
  elsif param.is_a?(String) and (match = param.match /^>(.*)/)
    suffix = match[1].size > 0 ? match[1] : param2
    write_to_file @builder.build_backtrace, suffix
  elsif param and param.match /\d+/
    index = param.to_i
    frame_manager.goto_index index
  else
    print_backtrace param
  end
end