Sha256: c2f418babba76c45642c65eba5db4a1de55234bdfe349d41cce671be33081b5c

Contents?: true

Size: 902 Bytes

Versions: 1

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

require "logger"
require_relative "../base"
require_relative "../setup/store"

class ExceptionsBase < Base
  include Setup::Store

  def call
    if corrected_word
      logger.error("\e[1;31m#{exception}\e[0m")
      logger.info("\e[1;32mRunning: #{corrected_cmd}\e[0m")

      pry.eval(corrected_cmd)
    else
      Pry::ExceptionHandler.handle_exception(output, exception, pry)
    end
  end

  private

  attr_reader :exception, :output, :pry

  def initialize(output, exception, pry)
    @output = output
    @exception = exception
    @pry = pry
  end

  def corrected_word
    @corrected_word ||= spell_checker.correct(unknown_from_exception).first
  end

  def spell_checker
    DidYouMean::SpellChecker.new(dictionary: dictionary)
  end

  def logger
    @logger = Logger.new($stdout)
  end

  def last_cmd
    @last_cmd ||= Pry.line_buffer.last.strip
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pry-byetypo-1.3.1 lib/pry-byetypo/exceptions/exceptions_base.rb