Class: PrettyTrace::BacktraceItem

Inherits:
Object
  • Object
show all
Includes:
Colors
Defined in:
lib/pretty_trace/backtrace_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Colors

#colors

Constructor Details

#initialize(original_line) ⇒ BacktraceItem

Returns a new instance of BacktraceItem.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pretty_trace/backtrace_item.rb', line 7

def initialize(original_line)
  @original_line = original_line
  @formatted = false

  return unless @original_line =~ /(.+):(-?\d+):in `(.+)'/

  @formatted = true
  @path = $1
  @line = $2
  @method = $3
  @full_dir = File.dirname(@path)
  @dir = @full_dir.split('/').last
  @dir = @dir == '.' ? '' : "#{dir}/"
  @file = File.basename @path
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



5
6
7
# File 'lib/pretty_trace/backtrace_item.rb', line 5

def dir
  @dir
end

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/pretty_trace/backtrace_item.rb', line 5

def file
  @file
end

#full_dirObject (readonly)

Returns the value of attribute full_dir.



5
6
7
# File 'lib/pretty_trace/backtrace_item.rb', line 5

def full_dir
  @full_dir
end

#lineObject (readonly)

Returns the value of attribute line.



5
6
7
# File 'lib/pretty_trace/backtrace_item.rb', line 5

def line
  @line
end

#methodObject (readonly)

Returns the value of attribute method.



5
6
7
# File 'lib/pretty_trace/backtrace_item.rb', line 5

def method
  @method
end

#original_lineObject (readonly)

Returns the value of attribute original_line.



5
6
7
# File 'lib/pretty_trace/backtrace_item.rb', line 5

def original_line
  @original_line
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/pretty_trace/backtrace_item.rb', line 5

def path
  @path
end

Instance Method Details

#colored_lineObject



31
32
33
# File 'lib/pretty_trace/backtrace_item.rb', line 31

def colored_line
  "line %{green_bold}#{line.to_s.ljust 4}%{reset} in %{cyan}#{dir}%{magenta}#{file}%{reset} > %{blue}#{method}%{reset}" % colors
end

#formatted?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pretty_trace/backtrace_item.rb', line 23

def formatted?
  @formatted
end

#formatted_lineObject



27
28
29
# File 'lib/pretty_trace/backtrace_item.rb', line 27

def formatted_line
  formatted? ? colored_line : original_line
end