rails.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. require 'rails/ruby_version_check'
  2. require 'pathname'
  3. require 'active_support'
  4. require 'active_support/core_ext/kernel/reporting'
  5. require 'active_support/core_ext/array/extract_options'
  6. require 'active_support/core_ext/logger'
  7. require 'rails/application'
  8. require 'rails/version'
  9. require 'active_support/railtie'
  10. require 'action_dispatch/railtie'
  11. # For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
  12. # multibyte safe operations. Plugin authors supporting other encodings
  13. # should override this behavior and set the relevant +default_charset+
  14. # on ActionController::Base.
  15. #
  16. # For Ruby 1.9, UTF-8 is the default internal and external encoding.
  17. if RUBY_VERSION < '1.9'
  18. $KCODE='u'
  19. else
  20. silence_warnings do
  21. Encoding.default_external = Encoding::UTF_8
  22. Encoding.default_internal = Encoding::UTF_8
  23. end
  24. end
  25. module Rails
  26. autoload :Info, 'rails/info'
  27. autoload :InfoController, 'rails/info_controller'
  28. class << self
  29. def application
  30. @@application ||= nil
  31. end
  32. def application=(application)
  33. @@application = application
  34. end
  35. # The Configuration instance used to configure the Rails environment
  36. def configuration
  37. application.config
  38. end
  39. def initialize!
  40. application.initialize!
  41. end
  42. def initialized?
  43. @@initialized || false
  44. end
  45. def initialized=(initialized)
  46. @@initialized ||= initialized
  47. end
  48. def logger
  49. @@logger ||= nil
  50. end
  51. def logger=(logger)
  52. @@logger = logger
  53. end
  54. def backtrace_cleaner
  55. @@backtrace_cleaner ||= begin
  56. # Relies on Active Support, so we have to lazy load to postpone definition until AS has been loaded
  57. require 'rails/backtrace_cleaner'
  58. Rails::BacktraceCleaner.new
  59. end
  60. end
  61. def root
  62. application && application.config.root
  63. end
  64. def env
  65. @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
  66. end
  67. def env=(environment)
  68. @_env = ActiveSupport::StringInquirer.new(environment)
  69. end
  70. def cache
  71. RAILS_CACHE
  72. end
  73. # Returns all rails groups for loading based on:
  74. #
  75. # * The Rails environment;
  76. # * The environment variable RAILS_GROUPS;
  77. # * The optional envs given as argument and the hash with group dependencies;
  78. #
  79. # == Examples
  80. #
  81. # groups :assets => [:development, :test]
  82. #
  83. # # Returns
  84. # # => [:default, :development, :assets] for Rails.env == "development"
  85. # # => [:default, :production] for Rails.env == "production"
  86. #
  87. def groups(*groups)
  88. hash = groups.extract_options!
  89. env = Rails.env
  90. groups.unshift(:default, env)
  91. groups.concat ENV["RAILS_GROUPS"].to_s.split(",")
  92. groups.concat hash.map { |k,v| k if v.map(&:to_s).include?(env) }
  93. groups.compact!
  94. groups.uniq!
  95. groups
  96. end
  97. def version
  98. VERSION::STRING
  99. end
  100. def public_path
  101. application && application.paths["public"].first
  102. end
  103. end
  104. end