From 61842d97c5269af8a36a33115f50543a155f1608 Mon Sep 17 00:00:00 2001 From: Ben Sandofsky Date: Fri, 1 Aug 2008 17:01:10 -0700 Subject: Make requiring gems optional. Signed-off-by: Michael Koziarski [#743 state:resolved] --- railties/lib/initializer.rb | 6 +++++- railties/lib/rails/gem_dependency.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index a2d08e2938..e876481cf1 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -688,13 +688,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 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 -- cgit v1.2.3 From 177a35e711e3b21eac0eb19f03aeae7626e490f5 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 2 Aug 2008 00:42:32 -0500 Subject: Added config.threadsafe! to toggle allow concurrency settings and disable the dependency loader --- railties/lib/initializer.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index e876481cf1..f8b3a78dff 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -768,6 +768,18 @@ 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.to_prepare { Rails.cache.threadsafe! } + 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. -- cgit v1.2.3 From e5b1ab7cc39ff57f9789ffda75fb33f72187775d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 6 Aug 2008 14:50:02 -0500 Subject: MemoryStore is the only "unsafe" store. Make it threadsafe by default. --- railties/lib/initializer.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index f8b3a78dff..4036b14f19 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -776,7 +776,6 @@ Run `rake gems:install` to install the missing gems. self.dependency_loading = false self.active_record.allow_concurrency = true self.action_controller.allow_concurrency = true - self.to_prepare { Rails.cache.threadsafe! } self end -- cgit v1.2.3 From f5bcbde1e387020c7f4968515921a3ccee3dcda2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 6 Aug 2008 17:40:03 -0500 Subject: Make sure ActionView is loaded inorder to build view paths --- railties/lib/initializer.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 4036b14f19..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) -- cgit v1.2.3 From 06e4eb49eaabde76e38e4f275619fe2df51f1e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez=20Troiti=C3=B1o?= Date: Mon, 4 Aug 2008 12:31:05 +0200 Subject: Added file name information for errors and exceptions in script/runnner Signed-off-by: Michael Koziarski --- railties/lib/commands/runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') 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 -- cgit v1.2.3 From eb4668b26ad4aacf79488d2bee553e9452971c35 Mon Sep 17 00:00:00 2001 From: Matthew Rudy Jacobs Date: Sat, 9 Aug 2008 17:04:54 +0100 Subject: rake db:fixtures:load and db:fixtures:identify now accept a FIXTURES_PATH option eg. "rake db:fixtures:load FIXTURES_PATH=spec/fixtures" Signed-off-by: Michael Koziarski [#792 state:committed] --- railties/lib/tasks/databases.rake | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'railties/lib') 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) -- cgit v1.2.3