aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-02 14:12:35 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-02 14:12:35 -0600
commitde2cd8e39f68d874b833b3a4860769c4edc57cbe (patch)
treeeb9ef69f38bf19dc79023971f8be964a95607746 /railties/lib
parent8db038227ca4cbcba01a86ef5fb94cb13c780463 (diff)
parentc446b1b12b6b54e61136410c6dfe69de3678eae9 (diff)
downloadrails-de2cd8e39f68d874b833b3a4860769c4edc57cbe.tar.gz
rails-de2cd8e39f68d874b833b3a4860769c4edc57cbe.tar.bz2
rails-de2cd8e39f68d874b833b3a4860769c4edc57cbe.zip
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails.rb21
-rw-r--r--railties/lib/rails/application.rb52
-rw-r--r--railties/lib/rails/commands/server.rb10
-rw-r--r--railties/lib/rails/initializable.rb22
-rw-r--r--railties/lib/rails/initializer.rb2
5 files changed, 42 insertions, 65 deletions
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb
index c23b67e321..b7cae9a9ac 100644
--- a/railties/lib/rails.rb
+++ b/railties/lib/rails.rb
@@ -1,5 +1,9 @@
require "pathname"
+require 'active_support'
+require 'active_support/core_ext/kernel/reporting'
+require 'active_support/core_ext/logger'
+
require 'rails/initializable'
require 'rails/application'
require 'rails/railties_path'
@@ -10,4 +14,19 @@ require 'rails/core'
require 'rails/configuration'
require 'rails/deprecation'
require 'rails/initializer'
-require 'rails/plugin' \ No newline at end of file
+require 'rails/plugin'
+require 'rails/ruby_version_check'
+
+# For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
+# multibyte safe operations. Plugin authors supporting other encodings
+# should override this behaviour and set the relevant +default_charset+
+# on ActionController::Base.
+#
+# For Ruby 1.9, UTF-8 is the default internal and external encoding.
+if RUBY_VERSION < '1.9'
+ $KCODE='u'
+else
+ Encoding.default_external = Encoding::UTF_8
+end
+
+RAILS_ENV = (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup unless defined?(RAILS_ENV) \ No newline at end of file
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 73198d68ca..110311558c 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -82,8 +82,21 @@ module Rails
@app.call(env)
end
- initializer :initialize_rails do
- Rails.run_initializers
+
+ # Loads the environment specified by Configuration#environment_path, which
+ # is typically one of development, test, or production.
+ initializer :load_environment do
+ next unless File.file?(config.environment_path)
+
+ config = self.config
+
+ Kernel.class_eval do
+ meth = instance_method(:config) if Object.respond_to?(:config)
+ define_method(:config) { config }
+ require config.environment_path
+ remove_method :config
+ define_method(:config, &meth) if meth
+ end
end
# Set the <tt>$LOAD_PATH</tt> based on the value of
@@ -97,18 +110,8 @@ module Rails
# list. By default, all frameworks (Active Record, Active Support,
# Action Pack, Action Mailer, and Active Resource) are loaded.
initializer :require_frameworks do
- begin
- require 'active_support'
- require 'active_support/core_ext/kernel/reporting'
- require 'active_support/core_ext/logger'
-
- # TODO: This is here to make Sam Ruby's tests pass. Needs discussion.
- require 'active_support/core_ext/numeric/bytes'
- config.frameworks.each { |framework| require(framework.to_s) }
- rescue LoadError => e
- # Re-raise as RuntimeError because Mongrel would swallow LoadError.
- raise e.to_s
- end
+ require 'active_support/all' unless config.active_support.bare
+ config.frameworks.each { |framework| require(framework.to_s) }
end
# Set the paths from which Rails will automatically load source files, and
@@ -137,24 +140,6 @@ module Rails
end
end
- # Loads the environment specified by Configuration#environment_path, which
- # is typically one of development, test, or production.
- initializer :load_environment do
- silence_warnings do
- next if @environment_loaded
- next unless File.file?(config.environment_path)
-
- @environment_loaded = true
- constants = self.class.constants
-
- eval(IO.read(config.environment_path), binding, config.environment_path)
-
- (self.class.constants - constants).each do |const|
- Object.const_set(const, self.class.const_get(const))
- end
- end
- end
-
# Preload all frameworks specified by the Configuration#frameworks.
# Used by Passenger to ensure everything's loaded before forking and
# to avoid autoload race conditions in JRuby.
@@ -312,9 +297,6 @@ module Rails
base_class.send("#{setting}=", value)
end
end
- config.active_support.each do |setting, value|
- ActiveSupport.send("#{setting}=", value)
- end
end
# Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index 57b7c6a49c..3687b4460e 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -41,9 +41,9 @@ module Rails
new(app).start
end
- def initialize(app)
+ def initialize(app_const)
super() # Call Rack::Server#initialize without passing any options to use.
- @app = app
+ @app_const = app_const
end
def start
@@ -69,7 +69,7 @@ module Rails
end
def log_path
- "#{File.expand_path(@app.root)}/log/#{options[:environment]}.log"
+ "#{File.expand_path(@app_const.root)}/log/#{options[:environment]}.log"
end
def default_options
@@ -77,10 +77,10 @@ module Rails
:Port => 3000,
:Host => "0.0.0.0",
:environment => (ENV['RAILS_ENV'] || "development").dup,
- :rack_file => "#{@app.root}/config.ru",
+ :rack_file => "#{@app_const.root}/config.ru",
:daemonize => false,
:debugger => false,
- :pid => "#{@app.root}/tmp/pids/server.pid",
+ :pid => "#{@app_const.root}/tmp/pids/server.pid",
:AccessLog => []
}
end
diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb
index 3866b856b2..96234739cf 100644
--- a/railties/lib/rails/initializable.rb
+++ b/railties/lib/rails/initializable.rb
@@ -106,26 +106,4 @@ module Rails
end
end
end
-
- include Initializable
-
- # Check for valid Ruby version (1.8.2 or 1.8.4 or higher). This is done in an
- # external file, so we can use it from the `rails` program as well without duplication.
- initializer :check_ruby_version, :global => true do
- require 'rails/ruby_version_check'
- end
-
- # For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
- # multibyte safe operations. Plugin authors supporting other encodings
- # should override this behaviour and set the relevant +default_charset+
- # on ActionController::Base.
- #
- # For Ruby 1.9, UTF-8 is the default internal and external encoding.
- initializer :initialize_encoding, :global => true do
- if RUBY_VERSION < '1.9'
- $KCODE='u'
- else
- Encoding.default_external = Encoding::UTF_8
- end
- end
end \ No newline at end of file
diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb
index 44101dcc94..95478428ec 100644
--- a/railties/lib/rails/initializer.rb
+++ b/railties/lib/rails/initializer.rb
@@ -1,7 +1,5 @@
require "rails" # In case people require this file directly
-RAILS_ENV = (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development').dup unless defined?(RAILS_ENV)
-
module Rails
class Initializer
class Error < StandardError ; end