class ConsistencyFail::Index

Attributes

columns[R]
model[R]
table_name[R]

Public Class Methods

new(model, table_name, columns) click to toggle source
# File lib/consistency_fail/index.rb, line 4
def initialize(model, table_name, columns)
  @model = model
  @table_name = table_name
  @columns = columns.map(&:to_s)
  handle_associations
end

Public Instance Methods

==(other) click to toggle source
# File lib/consistency_fail/index.rb, line 11
def ==(other)
  self.table_name == other.table_name &&
    self.columns.sort == other.columns.sort
end

Private Instance Methods

handle_associations() click to toggle source
# File lib/consistency_fail/index.rb, line 18
def handle_associations
  references = @model.reflect_on_all_associations(:belongs_to)
  names = references.map(&:name).map(&:to_s)
  @columns.map! do |column|
    next column unless names.include?(column)
    reflection = @model.reflect_on_association(column.to_sym)
    if reflection.options[:polymorphic]
      [reflection.foreign_key, reflection.foreign_type]
    else
      reflection.foreign_key
    end
  end
  @columns.flatten!
end