class TheSchemaIs::WrongColumnDefinition

Constants

MSG

Private Instance Methods

register_offense(_node) click to toggle source
# File lib/the_schema_is/cops.rb, line 212
def register_offense(_node)
  return if model.schema.nil? || schema.nil?

  wrong_columns
    .each do |mcol, scol|
      add_offense(mcol.source, message: MSG % scol.source.loc.expression.source) do |corrector|
        corrector.replace(mcol.source.loc.expression, scol.source.loc.expression.source)
      end
    end
end
wrong_columns() click to toggle source
# File lib/the_schema_is/cops.rb, line 223
def wrong_columns
  model_columns
    .map { |name, col| [col, schema_columns[name]] }
    .reject { |mcol, scol|
      # When column is not in schema, we shouldn't try to check it: UnknownColumn cop will
      # handle.
      !scol || mcol.type == scol.type && mcol.definition_source == scol.definition_source
    }
end