aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorHongli Lai (Phusion) <hongli@phusion.nl>2008-08-27 11:39:06 +0200
committerHongli Lai (Phusion) <hongli@phusion.nl>2008-08-27 11:39:06 +0200
commit08704c442d15b16511214731dd94108b737ef407 (patch)
treed92d53f39245256dea6aa38a11500938adccf777 /railties
parent920ad94598a9b90d048cb7cb19a34d7cb9e80392 (diff)
parent5db2f199aba9aa8d00adefa8237922ad684aca03 (diff)
downloadrails-08704c442d15b16511214731dd94108b737ef407.tar.gz
rails-08704c442d15b16511214731dd94108b737ef407.tar.bz2
rails-08704c442d15b16511214731dd94108b737ef407.zip
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/environments/production.rb3
-rw-r--r--railties/lib/commands/runner.rb2
-rw-r--r--railties/lib/initializer.rb33
-rw-r--r--railties/lib/rails/gem_dependency.rb2
-rw-r--r--railties/lib/tasks/databases.rake9
-rw-r--r--railties/test/gem_dependency_test.rb9
7 files changed, 47 insertions, 13 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 6df7c568dc..3a276d5aad 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*Edge*
+* Added config.threadsafe! to toggle allow concurrency settings and disable the dependency loader [Josh Peek]
+
* Turn cache_classes on by default [Josh Peek]
* Added configurable eager load paths. Defaults to app/models, app/controllers, and app/helpers [Josh Peek]
diff --git a/railties/environments/production.rb b/railties/environments/production.rb
index e915e8be73..ec5b7bc865 100644
--- a/railties/environments/production.rb
+++ b/railties/environments/production.rb
@@ -4,6 +4,9 @@
# Code is not reloaded between requests
config.cache_classes = true
+# Enable threaded mode
+# config.threadsafe!
+
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
diff --git a/railties/lib/commands/runner.rb b/railties/lib/commands/runner.rb
index 926bc26344..14159c3893 100644
--- a/railties/lib/commands/runner.rb
+++ b/railties/lib/commands/runner.rb
@@ -42,7 +42,7 @@ if code_or_file.nil?
$stderr.puts "Run '#{$0} -h' for help."
exit 1
elsif File.exist?(code_or_file)
- eval(File.read(code_or_file))
+ eval(File.read(code_or_file), nil, code_or_file)
else
eval(code_or_file)
end
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index a2d08e2938..6576cd368b 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -340,9 +340,11 @@ Run `rake gems:install` to install the missing gems.
end
def load_view_paths
- ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes
- ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer)
- ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller)
+ if configuration.frameworks.include?(:action_view)
+ ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes
+ ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller)
+ ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer)
+ end
end
# Eager load application classes
@@ -440,9 +442,11 @@ Run `rake gems:install` to install the missing gems.
# paths have already been set, it is not changed, otherwise it is
# set to use Configuration#view_path.
def initialize_framework_views
- view_path = ActionView::PathSet::Path.new(configuration.view_path, false)
- ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer)
- ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
+ if configuration.frameworks.include?(:action_view)
+ view_path = ActionView::PathSet::Path.new(configuration.view_path, false)
+ ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer)
+ ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
+ end
end
# If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
@@ -688,13 +692,17 @@ Run `rake gems:install` to install the missing gems.
# You can add gems with the #gem method.
attr_accessor :gems
- # Adds a single Gem dependency to the rails application.
+ # Adds a single Gem dependency to the rails application. By default, it will require
+ # the library with the same name as the gem. Use :lib to specify a different name.
#
# # gem 'aws-s3', '>= 0.4.0'
# # require 'aws/s3'
# config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
# :source => "http://code.whytheluckystiff.net"
#
+ # To require a library be installed, but not attempt to load it, pass :lib => false
+ #
+ # config.gem 'qrp', :version => '0.4.1', :lib => false
def gem(name, options = {})
@gems << Rails::GemDependency.new(name, options)
end
@@ -764,6 +772,17 @@ Run `rake gems:install` to install the missing gems.
::RAILS_ROOT.replace @root_path
end
+ # Enable threaded mode. Allows concurrent requests to controller actions and
+ # multiple database connections. Also disables automatic dependency loading
+ # after boot
+ def threadsafe!
+ self.cache_classes = true
+ self.dependency_loading = false
+ self.active_record.allow_concurrency = true
+ self.action_controller.allow_concurrency = true
+ self
+ end
+
# Loads and returns the contents of the #database_configuration_file. The
# contents of the file are processed via ERB before being sent through
# YAML::load.
diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb
index f8d97840c1..471e03fa5f 100644
--- a/railties/lib/rails/gem_dependency.rb
+++ b/railties/lib/rails/gem_dependency.rb
@@ -58,7 +58,7 @@ module Rails
def load
return if @loaded || @load_paths_added == false
- require(@lib || @name)
+ require(@lib || @name) unless @lib == false
@loaded = true
rescue LoadError
puts $!.to_s
diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake
index 5ec712a02d..21c81b3fb5 100644
--- a/railties/lib/tasks/databases.rake
+++ b/railties/lib/tasks/databases.rake
@@ -182,11 +182,11 @@ namespace :db do
end
namespace :fixtures do
- desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
+ desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
task :load => :environment do
require 'active_record/fixtures'
ActiveRecord::Base.establish_connection(Rails.env)
- base_dir = File.join(Rails.root, 'test', 'fixtures')
+ base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : File.join(Rails.root, 'test', 'fixtures')
fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
@@ -194,7 +194,7 @@ namespace :db do
end
end
- desc "Search for a fixture given a LABEL or ID."
+ desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
task :identify => :environment do
require "active_record/fixtures"
@@ -203,7 +203,8 @@ namespace :db do
puts %Q(The fixture ID for "#{label}" is #{Fixtures.identify(label)}.) if label
- Dir["#{RAILS_ROOT}/test/fixtures/**/*.yml"].each do |file|
+ base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : File.join(Rails.root, 'test', 'fixtures')
+ Dir["#{base_dir}/**/*.yml"].each do |file|
if data = YAML::load(ERB.new(IO.read(file)).result)
data.keys.each do |key|
key_id = Fixtures.identify(key)
diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb
index b5946aa7b8..964ca50992 100644
--- a/railties/test/gem_dependency_test.rb
+++ b/railties/test/gem_dependency_test.rb
@@ -11,6 +11,7 @@ uses_mocha "Plugin Tests" do
@gem_with_source = Rails::GemDependency.new "hpricot", :source => "http://code.whytheluckystiff.net"
@gem_with_version = Rails::GemDependency.new "hpricot", :version => "= 0.6"
@gem_with_lib = Rails::GemDependency.new "aws-s3", :lib => "aws/s3"
+ @gem_without_load = Rails::GemDependency.new "hpricot", :lib => false
end
def test_configuration_adds_gem_dependency
@@ -62,5 +63,13 @@ uses_mocha "Plugin Tests" do
@gem_with_lib.add_load_paths
@gem_with_lib.load
end
+
+ def test_gem_without_lib_loading
+ @gem_without_load.expects(:gem).with(@gem_without_load.name)
+ @gem_without_load.expects(:require).with(@gem_without_load.lib).never
+ @gem_without_load.add_load_paths
+ @gem_without_load.load
+ end
+
end
end