lib/lookbook/error.rb in lookbook-1.5.5 vs lib/lookbook/error.rb in lookbook-2.0.0.beta.0
- old
+ new
@@ -1,8 +1,8 @@
module Lookbook
class Error < StandardError
- delegate :full_message, :backtrace, :to_s, to: :target
+ delegate :full_message, :backtrace, :to_s, to: :original
LINES_AROUND = 3
def initialize(original = nil, title: nil, message: nil, file_path: nil, file_name: nil, line_number: nil, source_code: nil)
@original = original
@@ -57,15 +57,15 @@
lang = Lookbook::Lang.guess(file_path)
lang.present? ? lang[:name] : "plaintext"
end
def title
- @title || target.class.to_s
+ @title || original.class.to_s
end
def message
- (@message || target.message).gsub("(<unknown>):", "").strip.upcase_first
+ (@message || original.message).gsub("(<unknown>):", "").strip.upcase_first
end
def file_name
if @file_name == false
nil
@@ -78,11 +78,11 @@
path = if @file_path.nil?
parsed_backtrace[0][0] if parsed_backtrace.any?
else
@file_path.presence || nil
end
- path&.to_s&.delete_prefix("#{Rails.root}/")
+ path.nil? ? nil : path.to_s.delete_prefix("#{Rails.root}/")
end
def line_number
number = if @line_number.nil?
parsed_backtrace[0][1] if parsed_backtrace.any?
@@ -99,10 +99,10 @@
end
end
protected
- def target
+ def original
@original.presence || self
end
def source_code_start_line(lines)
[(line_number - LINES_AROUND), 1].max unless line_number.nil?