Sha256: 76b0f10ca1a0d876ee332d67ee266f82a6189d9ad2502737eb134ae624313e11

Contents?: true

Size: 744 Bytes

Versions: 3

Compression:

Stored size: 744 Bytes

Contents

# frozen_string_literal: true

require_relative "../base"

module Exceptions
  module ActiveRecord
    module StatementInvalid
      class UndefinedColumn < Base
        private

        def can_correct?
          corrected_word.present?
        end

        def unknown_from_exception
          exception.to_s.match(exception_regexp)[1]
        end

        def corrected_word
          match = exception.to_s.match(hint_regexp)
          return if match.nil?

          match[1].split(".").last
        end

        # The not found column name
        def exception_regexp
          /column \w+\.(\w+)\s/
        end

        # The hint generated by PG
        def hint_regexp
          /"(\w+\.\w+)"/
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pry-byetypo-1.3.5 lib/pry-byetypo/exceptions/active_record/statement_invalid/undefined_column.rb
pry-byetypo-1.3.4 lib/pry-byetypo/exceptions/active_record/statement_invalid/undefined_column.rb
pry-byetypo-1.3.3 lib/pry-byetypo/exceptions/active_record/statement_invalid/undefined_column.rb