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)
-
(Schema, nil)
-
def load(target_ruby_version) return @load if defined?(@load) @load = load!(target_ruby_version) end
def load!(target_ruby_version)
def load!(target_ruby_version) path = db_schema_path return unless path ast = parse(path, target_ruby_version) Schema.new(ast) end
def parse(path, target_ruby_version)
def parse(path, target_ruby_version) klass_name = :"Ruby#{target_ruby_version.to_s.sub('.', '')}" klass = ::Parser.const_get(klass_name) parser = klass.new(RuboCop::AST::Builder.new) buffer = Parser::Source::Buffer.new(path, 1) buffer.source = path.read parser.parse(buffer) end
def reset!
def reset! return unless instance_variable_defined?(:@load) remove_instance_variable(:@load) end