Class: PrettyTrace::BacktraceItem
- Inherits:
-
Object
- Object
- PrettyTrace::BacktraceItem
- Includes:
- Colors
- Defined in:
- lib/pretty_trace/backtrace_item.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#full_dir ⇒ Object
readonly
Returns the value of attribute full_dir.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#original_line ⇒ Object
readonly
Returns the value of attribute original_line.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #colored_line ⇒ Object
- #formatted? ⇒ Boolean
- #formatted_line ⇒ Object
-
#initialize(original_line) ⇒ BacktraceItem
constructor
A new instance of BacktraceItem.
Methods included from 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
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
5 6 7 |
# File 'lib/pretty_trace/backtrace_item.rb', line 5 def dir @dir end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/pretty_trace/backtrace_item.rb', line 5 def file @file end |
#full_dir ⇒ Object (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 |
#line ⇒ Object (readonly)
Returns the value of attribute line.
5 6 7 |
# File 'lib/pretty_trace/backtrace_item.rb', line 5 def line @line end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
5 6 7 |
# File 'lib/pretty_trace/backtrace_item.rb', line 5 def method @method end |
#original_line ⇒ Object (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 |
#path ⇒ Object (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_line ⇒ Object
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
23 24 25 |
# File 'lib/pretty_trace/backtrace_item.rb', line 23 def formatted? @formatted end |
#formatted_line ⇒ Object
27 28 29 |
# File 'lib/pretty_trace/backtrace_item.rb', line 27 def formatted_line formatted? ? colored_line : original_line end |