class RuboCop::Rails::SchemaLoader::Schema

Represent db/schema.rb

def add_indices_by(table_name:)

def add_indices_by(table_name:)
  add_indices.select do |add_index|
    add_index.table_name == table_name
  end
end

def build!(ast)

def build!(ast)
  raise "Unexpected type: #{ast.type}" unless ast.block_type?
  return unless ast.body
  each_table(ast) do |table_def|
    next unless table_def.method?(:create_table)
    @tables << Table.new(table_def)
  end
  # Compatibility for Rails 4.2.
  each_add_index(ast) do |add_index_def|
    @add_indices << AddIndex.new(add_index_def)
  end
end

def each_add_index(ast)

def each_add_index(ast)
  ast.body.children.each do |node|
    next unless node.respond_to?(:send_type?)
    next if !node&.send_type? || !node.method?(:add_index)
    yield(node)
  end
end

def each_table(ast)

def each_table(ast)
  case ast.body.type
  when :begin
    ast.body.children.each do |node|
      next unless node.block_type? && node.method?(:create_table)
      yield(node)
    end
  else
    yield ast.body
  end
end

def initialize(ast)

def initialize(ast)
  @tables = []
  @add_indices = []
  build!(ast)
end

def table_by(name:)

def table_by(name:)
  tables.find do |table|
    table.name == name
  end
end