Exception: DatabaseValidations::Errors::IndexNotFound

Inherits:
Base
  • Object
show all
Defined in:
lib/database_validations/lib/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#env_message

Constructor Details

#initialize(columns, where_clause, index_name, available_indexes, table_name) ⇒ IndexNotFound

Returns a new instance of IndexNotFound.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Instance Attribute Details

#available_indexesObject (readonly)

Returns the value of attribute available_indexes.



10
11
12
# File 'lib/database_validations/lib/errors.rb', line 10

def available_indexes
  @available_indexes
end

#columnsObject (readonly)

Returns the value of attribute columns.



10
11
12
# File 'lib/database_validations/lib/errors.rb', line 10

def columns
  @columns
end

#index_nameObject (readonly)

Returns the value of attribute index_name.



10
11
12
# File 'lib/database_validations/lib/errors.rb', line 10

def index_name
  @index_name
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



10
11
12
# File 'lib/database_validations/lib/errors.rb', line 10

def table_name
  @table_name
end

#where_clauseObject (readonly)

Returns the value of attribute where_clause.



10
11
12
# File 'lib/database_validations/lib/errors.rb', line 10

def where_clause
  @where_clause
end

Instance Method Details

#columns_and_where_text(columns, where) ⇒ Object



30
31
32
# File 'lib/database_validations/lib/errors.rb', line 30

def columns_and_where_text(columns, where)
  "columns: #{columns}#{" and where: #{where}" if where}"
end