module RuboCop::Rails::SchemaLoader

def db_schema_path

def db_schema_path
  path = Pathname.pwd
  until path.root?
    schema_path = path.join('db/schema.rb')
    return schema_path if schema_path.exist?
    path = path.join('../').cleanpath
  end
  nil
end

def load(target_ruby_version, parser_engine)

Returns:
  • (Schema, nil) -
def load(target_ruby_version, parser_engine)
  return @load if defined?(@load)
  @load = load!(target_ruby_version, parser_engine)
end

def load!(target_ruby_version, parser_engine)

def load!(target_ruby_version, parser_engine)
  path = db_schema_path
  return unless path
  ast = RuboCop::ProcessedSource.new(File.read(path), target_ruby_version, path, parser_engine: parser_engine).ast
  Schema.new(ast) if ast
end

def reset!

def reset!
  return unless instance_variable_defined?(:@load)
  remove_instance_variable(:@load)
end