Sha256: 02ca91f345ab03347b72b30eaf31242a9fb21d25a477ba62b61498165b6ac752

Contents?: true

Size: 663 Bytes

Versions: 12

Compression:

Stored size: 663 Bytes

Contents

module DidYouMean
  class SimilarAttributeFinder
    include BaseFinder
    attr_reader :columns, :attribute_name

    def initialize(exception)
      @columns        = exception.frame_binding.eval("self.class").columns
      @attribute_name = (/unknown attribute(: | ')(\w+)/ =~ exception.original_message) && $2
    end

    def words
      columns.map(&:name)
    end

    alias target_word attribute_name

    def format(column_name)
      "%{column}: %{type}" % {
        column: column_name,
        type:   columns.detect{|c| c.name == column_name }.type
      }
    end
  end

  finders["ActiveRecord::UnknownAttributeError"] = SimilarAttributeFinder
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
did_you_mean-0.9.10-java lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.10 lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.9-java lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.9 lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.8 lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.7 lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.6-java lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.6 lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.5 lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.4 lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.2 lib/did_you_mean/finders/similar_attribute_finder.rb
did_you_mean-0.9.0 lib/did_you_mean/finders/similar_attribute_finder.rb