From 346bb018499cde6699fcce6c68dd7e9be45c75e1 Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Fri, 4 May 2012 18:40:32 +0400 Subject: More faster rails dbconsole --- railties/lib/rails/commands/dbconsole.rb | 38 +++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'railties/lib/rails/commands/dbconsole.rb') diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index 25a8caeec3..aaba47117f 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -5,15 +5,37 @@ require 'rbconfig' module Rails class DBConsole - attr_reader :arguments + attr_reader :arguments, :config - def self.start(app) - new(app).start + def self.start + new(config).start end - def initialize(app, arguments = ARGV) - @app = app - @arguments = arguments + def self.config + config = begin + YAML.load(ERB.new(IO.read("config/database.yml")).result) + rescue SyntaxError, StandardError + require APP_PATH + Rails.application.config.database_configuration + end + + unless config[env] + abort "No database is configured for the environment '#{env}'" + end + + config[env] + end + + def self.env + if Rails.respond_to?(:env) + Rails.env + else + ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" + end + end + + def initialize(config, arguments = ARGV) + @config, @arguments = config, arguments end def start @@ -38,10 +60,6 @@ module Rails abort opt.to_s unless (0..1).include?(arguments.size) end - unless config = @app.config.database_configuration[Rails.env] - abort "No database is configured for the environment '#{Rails.env}'" - end - case config["adapter"] when /^mysql/ -- cgit v1.2.3