Sha256: 19aade4369e58f8b33f834c0a454f22981618c6de79c9cc8da1d4b9cfee115e6

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Lookbook
  class Error < StandardError
    delegate :full_message, :backtrace, :to_s, to: :target

    def initialize(original = nil, title: nil, message: nil, file_name: false, line_number: false)
      @original = original
      @title = title
      @message = message
      @file_name = file_name
      @line_number = line_number
      super()
    end

    def title
      @title || target.class.to_s
    end

    def message
      (@message || target.message).gsub("(<unknown>):", "").strip.upcase_first
    end

    def file_name
      path = if @file_name == false
        parsed_backtrace[0][0] if parsed_backtrace.any?
      else
        @file_name
      end
      path.delete_prefix("#{Rails.root}/")
    end

    def line_number
      if @line_number == false
        parsed_backtrace[0][1] if parsed_backtrace.any?
      else
        @line_number
      end
    end

    def parsed_backtrace
      backtrace.map do |x|
        x =~ /^(.+?):(\d+)(|:in `(.+)')$/
        [$1, $2, $4]
      end
    end

    protected

    def target
      @original.presence || self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lookbook-0.7.2.beta.0 lib/lookbook/error.rb