1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/rails/command/environment_argument.rb
Matthew Draper 87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30

34 lines
948 B
Ruby

require "active_support"
module Rails
module Command
module EnvironmentArgument #:nodoc:
extend ActiveSupport::Concern
included do
argument :environment, optional: true, banner: "environment"
end
private
def extract_environment_option_from_argument
if environment
self.options = options.merge(environment: acceptable_environment(environment))
elsif !options[:environment]
self.options = options.merge(environment: Rails::Command.environment)
end
end
def acceptable_environment(env = nil)
if available_environments.include? env
env
else
%w( production development test ).detect { |e| e =~ /^#{env}/ } || env
end
end
def available_environments
Dir["config/environments/*.rb"].map { |fname| File.basename(fname, ".*") }
end
end
end
end