class DatabaseValidations::Errors::IndexNotFound

Attributes

available_indexes[R]
columns[R]
index_name[R]
table_name[R]
where_clause[R]

Public Class Methods

new(columns, where_clause, index_name, available_indexes, table_name) click to toggle source
Calls superclass method
# File lib/database_validations/lib/errors.rb, line 12
def initialize(columns, where_clause, index_name, available_indexes, table_name)
  @columns = columns
  @where_clause = where_clause
  @available_indexes = available_indexes
  @index_name = index_name

  text = if index_name
           "No unique index found with name: \"#{index_name}\" in table \"#{table_name}\". "\
           "Available indexes are: #{self.available_indexes.map(&:name)}. "
         else
           available_indexes = self.available_indexes.map { |ind| columns_and_where_text(ind.columns, ind.where) }.join(', ')
           "No unique index found with #{columns_and_where_text(columns, where_clause)} in table \"#{table_name}\". "\
           "Available indexes are: [#{available_indexes}]. "
         end

  super text + env_message
end

Public Instance Methods

columns_and_where_text(columns, where) click to toggle source
# File lib/database_validations/lib/errors.rb, line 30
def columns_and_where_text(columns, where)
  "columns: #{columns}#{" and where: #{where}" if where}"
end