diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-01-04 14:03:24 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-01-04 14:03:24 -0800 |
commit | fab7c5358580e2672eb64ba9539afe00f8ab78e3 (patch) | |
tree | aac41e928c2f201d8dc610e85fbc302d641f01e6 /railties/lib | |
parent | d2bc6f9df6362a0892787b23ec8a68cef7a3e965 (diff) | |
parent | 4fa6088b428e8a8a567cde1f660a209113f04dc3 (diff) | |
download | rails-fab7c5358580e2672eb64ba9539afe00f8ab78e3.tar.gz rails-fab7c5358580e2672eb64ba9539afe00f8ab78e3.tar.bz2 rails-fab7c5358580e2672eb64ba9539afe00f8ab78e3.zip |
Merge pull request #8633 from mykola-kyryk/issue_8628
Allow environment name to start with a substring of the default
environment names.
Fixes #8628
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands/console.rb | 11 | ||||
-rw-r--r-- | railties/lib/rails/commands/dbconsole.rb | 10 |
2 files changed, 19 insertions, 2 deletions
diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index aef7600fbd..35a9072f51 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -24,11 +24,20 @@ module Rails if arguments.first && arguments.first[0] != '-' env = arguments.first - options[:environment] = %w(production development test).detect {|e| e =~ /^#{env}/} || env + if available_environments.include? env + options[:environment] = env + else + options[:environment] = %w(production development test).detect {|e| e =~ /^#{env}/} || env + end end options end + + private + def available_environments + Dir[Rails.root.join('config', 'environments', '*.rb')].map { |fname| File.basename(fname, '.*') } + end end attr_reader :options, :app, :console diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index 4a5674236d..353a64fd01 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -136,12 +136,20 @@ module Rails if arguments.first && arguments.first[0] != '-' env = arguments.first - options[:environment] = %w(production development test).detect {|e| e =~ /^#{env}/} || env + if self.class.available_environments.include? env + options[:environment] = env + else + options[:environment] = %w(production development test).detect {|e| e =~ /^#{env}/} || env + end end options end + def self.available_environments + Dir[Rails.root.join('config', 'environments', '*.rb')].map { |fname| File.basename(fname, '.*') } + end + def find_cmd_and_exec(commands, *args) commands = Array(commands) |