diff options
author | Dmitry Vorotilin <d.vorotilin@gmail.com> | 2012-05-04 18:40:32 +0400 |
---|---|---|
committer | Dmitry Vorotilin <d.vorotilin@gmail.com> | 2012-05-06 22:53:53 +0400 |
commit | 346bb018499cde6699fcce6c68dd7e9be45c75e1 (patch) | |
tree | ed6c4db36a0ce2fd479a4d18493be692170a90fa /railties/lib | |
parent | ed1703bcb206a740957c0a93df5f25177dedc0de (diff) | |
download | rails-346bb018499cde6699fcce6c68dd7e9be45c75e1.tar.gz rails-346bb018499cde6699fcce6c68dd7e9be45c75e1.tar.bz2 rails-346bb018499cde6699fcce6c68dd7e9be45c75e1.zip |
More faster rails dbconsole
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/commands/dbconsole.rb | 38 |
2 files changed, 29 insertions, 12 deletions
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 82cdd6053b..7f473c237c 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -57,8 +57,7 @@ when 'server' when 'dbconsole' require 'rails/commands/dbconsole' - require APP_PATH - Rails::DBConsole.start(Rails.application) + Rails::DBConsole.start when 'application', 'runner' require "rails/commands/#{command}" 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/ |