Module: Mentor::Outputs
- Includes:
- OutputHelper
- Included in:
- Backtrace, DidYouMeanCorrection, ErrorClassSpecificHelp, Header, LineOfCode, LinesOfCode, MentorError, MentorNoMethodError, RelativePath, RubyErrorComplete, RubyErrorMain, Suggestion
- Defined in:
- lib/helpers/outputs.rb
Instance Method Summary
collapse
#home_to_tilde, #indent_lines, #lines_from_file, #terminal_width, #valid_var_name
Instance Method Details
#absolute_base_dir ⇒ Object
7
8
9
|
# File 'lib/helpers/outputs.rb', line 7
def absolute_base_dir
Dir.pwd + '/'
end
|
#app_dir ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/helpers/outputs.rb', line 11
def app_dir
Mentor.tp.path. sub(absolute_base_dir, ''). split('/')[0..-2]. join('/') + '/' end
|
#backtrace_lines ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/helpers/outputs.rb', line 19
def backtrace_lines
if self.class.class_variable_defined?(:@@backtrace_lines)
return @@backtrace_lines
end
bt_lines = Mentor.tp.raised_exception.
backtrace[1..-1]. grep_v(/bin\/mentor/). map { |line| line.sub(Dir.pwd + '/', '') }. map { |line| 'from ' + line }
return bt_lines if bt_lines.empty?
bt_lines[-1].gsub!("`<top (required)>'", "`<main>'")
@@backtrace_lines = bt_lines
end
|
#calling_method ⇒ Object
42
43
44
|
# File 'lib/helpers/outputs.rb', line 42
def calling_method
(Mentor.tp.method_id || '<main>').to_s
end
|
#did_you_mean_text ⇒ Object
52
53
54
|
# File 'lib/helpers/outputs.rb', line 52
def did_you_mean_text
'Did you mean?'
end
|
#did_you_mean_word ⇒ Object
46
47
48
49
50
|
# File 'lib/helpers/outputs.rb', line 46
def did_you_mean_word
if Mentor.tp.raised_exception.respond_to? :corrections
Mentor.tp.raised_exception.corrections.first&.to_s
end
end
|
#error_lineno ⇒ Object
60
61
62
|
# File 'lib/helpers/outputs.rb', line 60
def error_lineno
Mentor.tp.lineno.to_s
end
|
#error_lineno_padded(width) ⇒ Object
56
57
58
|
# File 'lib/helpers/outputs.rb', line 56
def error_lineno_padded(width)
"=> #{@lineno}".rjust(width)
end
|
#file_name ⇒ Object
64
65
66
|
# File 'lib/helpers/outputs.rb', line 64
def file_name
Mentor.tp.path.split('/').last
end
|
#horizontal_line ⇒ Object
68
69
70
|
# File 'lib/helpers/outputs.rb', line 68
def horizontal_line
'─' * terminal_width
end
|
#instance_methods ⇒ Object
72
73
74
75
|
# File 'lib/helpers/outputs.rb', line 72
def instance_methods
Mentor.tp.raised_exception.receiver.class.instance_methods -
Mentor.tp.raised_exception.receiver.class.superclass.instance_methods
end
|
#lineno_subtle_padded(width) ⇒ Object
77
78
79
|
# File 'lib/helpers/outputs.rb', line 77
def lineno_subtle_padded(width)
@lineno.to_s.rjust(width)
end
|
#message ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/helpers/outputs.rb', line 81
def message
if Mentor.tp.raised_exception.respond_to? :original_message
Mentor.tp.raised_exception.original_message
else
Mentor.tp.raised_exception.message
end
end
|
#method_class ⇒ Object
99
100
101
102
103
|
# File 'lib/helpers/outputs.rb', line 99
def method_class
if Mentor.tp.raised_exception.respond_to? :receiver
Mentor.tp.raised_exception.receiver.class.to_s
end
end
|
#method_class_plural ⇒ Object
105
106
107
|
# File 'lib/helpers/outputs.rb', line 105
def method_class_plural
pluralize method_class
end
|
#method_class_superclass ⇒ Object
109
110
111
|
# File 'lib/helpers/outputs.rb', line 109
def method_class_superclass
Mentor.tp.raised_exception.receiver.class.superclass
end
|
#method_class_superclasses ⇒ Object
113
114
115
|
# File 'lib/helpers/outputs.rb', line 113
def method_class_superclasses
to_sentence(Mentor.tp.raised_exception.receiver.class.ancestors - typical_classes)
end
|
#method_name ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/helpers/outputs.rb', line 89
def method_name
if Mentor.tp.raised_exception.respond_to? :spell_checker
if Mentor.tp.raised_exception.spell_checker.respond_to?(:method_name)
Mentor.tp.raised_exception.spell_checker.method_name.to_s
else
raise "cannot determine method name"
end
end
end
|
#relative_base_dir ⇒ Object
117
118
119
|
# File 'lib/helpers/outputs.rb', line 117
def relative_base_dir
home_to_tilde(absolute_base_dir)
end
|
#ruby_error_class ⇒ Object
121
122
123
|
# File 'lib/helpers/outputs.rb', line 121
def ruby_error_class
Mentor.tp.raised_exception.class.to_s
end
|
#ruby_error_text ⇒ Object
125
126
127
|
# File 'lib/helpers/outputs.rb', line 125
def ruby_error_text
'Ruby Error:'
end
|
#var_for_method ⇒ Object
129
130
131
132
133
134
135
136
|
# File 'lib/helpers/outputs.rb', line 129
def var_for_method
culprit_line = lines_from_file[Mentor.tp.lineno]
var = culprit_line[/#{valid_var_name}\.#{method_name}/].to_s.chomp(".#{method_name}")
if var.empty?
culprit_line[/#{valid_var_name} method_name/].to_s.chomp(".#{method_name}")
end
var
end
|