Class: Pakyow::Error::CLIFormatter Private
- Inherits:
-
Object
- Object
- Pakyow::Error::CLIFormatter
- Defined in:
- lib/pakyow/error.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- HIGHLIGHT_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/`([^']*)'/
Class Method Summary collapse
- .format(message) ⇒ Object private
- .indent(message) ⇒ Object private
Instance Method Summary collapse
- #backtrace ⇒ Object private
- #details ⇒ Object private
- #header ⇒ Object private
-
#initialize(error) ⇒ CLIFormatter
constructor
private
A new instance of CLIFormatter.
- #message ⇒ Object private
- #to_s ⇒ Object private
Constructor Details
#initialize(error) ⇒ CLIFormatter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CLIFormatter.
191 192 193 |
# File 'lib/pakyow/error.rb', line 191 def initialize(error) @error = error end |
Class Method Details
.format(message) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
263 264 265 266 267 268 269 |
# File 'lib/pakyow/error.rb', line 263 def format() .dup.tap do || .scan(HIGHLIGHT_REGEX).each do |match| .gsub!("`#{match[0]}'", Support::CLI.style.italic.blue(match[0])) end end end |
.indent(message) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
253 254 255 256 257 |
# File 'lib/pakyow/error.rb', line 253 def indent() .split("\n").map { |line| " #{line}" }.join("\n") end |
Instance Method Details
#backtrace ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
245 246 247 |
# File 'lib/pakyow/error.rb', line 245 def backtrace @error.condensed_backtrace.map(&:to_s).join("\n") end |
#details ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
241 242 243 |
# File 'lib/pakyow/error.rb', line 241 def details Support::CLI.style.bright_black(self.class.indent(self.class.format(@error.details))) end |
#header ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/pakyow/error.rb', line 209 def header start = " #{@error.name.upcase} " finish = if @error.project? File.basename(@error.path) else "" end "#{start}#{" " * (80 - (start.length + finish.length + 2))} #{finish} " end |
#message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/pakyow/error.rb', line 221 def = Support::CLI.style.white.on_red.bold(header) = @error..split("\n") if .any? << "\n\n#{self.class.indent(Support::CLI.style.red("›") + Support::CLI.style.bright_black(" #{self.class.format(.shift)}"))}\n" .each do |line| << Support::CLI.style.bright_black("\n#{line}") end end if @error.respond_to?(:contextual_message) = <<~MESSAGE #{} #{Support::CLI.style.bright_black(self.class.indent(self.class.format(@error.)))} MESSAGE end .rstrip end |
#to_s ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/pakyow/error.rb', line 195 def to_s <<~MESSAGE #{} #{Support::CLI.style.black.on_white.bold(" DETAILS ")} #{details} #{Support::CLI.style.black.on_white.bold(" BACKTRACE ")} #{backtrace} MESSAGE end |