aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands/console_helper.rb
blob: 48c489740e24cd3f9b9b29f71602d00a7810bd52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "active_support/concern"

module Rails
  module ConsoleHelper # :nodoc:
    extend ActiveSupport::Concern

    module ClassMethods
      def start(*args)
        new(*args).start
      end
      
      private
        def set_options_env(arguments, options)
          if arguments.first && arguments.first[0] != "-"
            env = arguments.first
            if available_environments.include? env
              options[:environment] = env
            else
              options[:environment] = %w(production development test).detect { |e| e =~ /^#{env}/ } || env
            end
          end
          options
        end

        def available_environments
          Dir["config/environments/*.rb"].map { |fname| File.basename(fname, ".*") }
        end  
    end

    def environment
      ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
    end
  end
end