From 0d241f4434bafa2107cd6c3f3ab77c05f5d5ec71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapaj=C3=B3s?= Date: Sun, 13 Jul 2008 14:19:03 -0500 Subject: Use full path in database tasks so commands will work outside of Rails root [#612 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/tasks/databases.rake | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 75fba8b45a..22b8459ce4 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -215,14 +215,14 @@ namespace :db do desc "Create a db/schema.rb file that can be portably used against any DB supported by AR" task :dump => :environment do require 'active_record/schema_dumper' - File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file| + File.open(ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb", "w") do |file| ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file) end end desc "Load a schema.rb file into the database" task :load => :environment do - file = ENV['SCHEMA'] || "db/schema.rb" + file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb" load(file) end end @@ -234,7 +234,7 @@ namespace :db do case abcs[RAILS_ENV]["adapter"] when "mysql", "oci", "oracle" ActiveRecord::Base.establish_connection(abcs[RAILS_ENV]) - File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } + File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } when "postgresql" ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"] ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"] @@ -252,13 +252,13 @@ namespace :db do when "firebird" set_firebird_env(abcs[RAILS_ENV]) db_string = firebird_db_string(abcs[RAILS_ENV]) - sh "isql -a #{db_string} > db/#{RAILS_ENV}_structure.sql" + sh "isql -a #{db_string} > #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql" else raise "Task not supported by '#{abcs["test"]["adapter"]}'" end if ActiveRecord::Base.connection.supports_migrations? - File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } + File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } end end end @@ -281,28 +281,28 @@ namespace :db do when "mysql" ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') - IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| + IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| ActiveRecord::Base.connection.execute(table) end when "postgresql" ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"] - `psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}` + `psql -U "#{abcs["test"]["username"]}" -f #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}` when "sqlite", "sqlite3" dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"] - `#{abcs["test"]["adapter"]} #{dbfile} < db/#{RAILS_ENV}_structure.sql` + `#{abcs["test"]["adapter"]} #{dbfile} < #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql` when "sqlserver" `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql` when "oci", "oracle" ActiveRecord::Base.establish_connection(:test) - IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl| + IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl| ActiveRecord::Base.connection.execute(ddl) end when "firebird" set_firebird_env(abcs["test"]) db_string = firebird_db_string(abcs["test"]) - sh "isql -i db/#{RAILS_ENV}_structure.sql #{db_string}" + sh "isql -i #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{db_string}" else raise "Task not supported by '#{abcs["test"]["adapter"]}'" end -- cgit v1.2.3 From 697ee1a50dea7580a7240535d3ad89d2d090721a Mon Sep 17 00:00:00 2001 From: Jacek Becela Date: Wed, 9 Jul 2008 21:34:04 +0200 Subject: Enable loading fixtures from arbitrary locations. [#586 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/tasks/databases.rake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 22b8459ce4..87934c295e 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -179,12 +179,15 @@ namespace :db do end namespace :fixtures do - desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y" + 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." task :load => :environment do require 'active_record/fixtures' - ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) - (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| - Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*')) + ActiveRecord::Base.establish_connection(Rails.env) + base_dir = 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| + Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*')) end end -- cgit v1.2.3 From 5c086070824bf7dd2bc4c9ce97956d82ac3fa206 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 13 Jul 2008 22:24:16 -0400 Subject: Make script/plugin install -r option work with git based plugins. [#257 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/commands/plugin.rb | 47 ++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index ce4b0d051d..0256090d16 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -43,6 +43,16 @@ # plugin is pulled via `svn checkout` or `svn export` but looks # exactly the same. # +# Specifying revisions: +# +# * Subversion revision is a single integer. +# +# * Git revision format: +# - full - 'refs/tags/1.8.0' or 'refs/heads/experimental' +# - short: 'experimental' (equivalent to 'refs/heads/experimental') +# 'tag 1.8.0' (equivalent to 'refs/tags/1.8.0') +# +# # This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com) # and is licensed MIT: (http://www.opensource.org/licenses/mit-license.php) @@ -175,7 +185,7 @@ class Plugin method ||= rails_env.best_install_method? if :http == method method = :export if svn_url? - method = :clone if git_url? + method = :git if git_url? end uninstall if installed? and options[:force] @@ -255,8 +265,25 @@ class Plugin end end - def install_using_clone(options = {}) - git_command :clone, options + def install_using_git(options = {}) + root = rails_env.root + install_path = mkdir_p "#{root}/vendor/plugins/#{name}" + Dir.chdir install_path do + init_cmd = "git init" + init_cmd += " -q" if options[:quiet] and not $verbose + puts init_cmd if $verbose + system(init_cmd) + base_cmd = "git pull --depth 1 #{uri}" + base_cmd += " -q" if options[:quiet] and not $verbose + base_cmd += " #{options[:revision]}" if options[:revision] + puts base_cmd if $verbose + if system(base_cmd) + puts "removing: .git" if $verbose + rm_rf ".git" + else + rm_rf install_path + end + end end def svn_command(cmd, options = {}) @@ -268,16 +295,6 @@ class Plugin puts base_cmd if $verbose system(base_cmd) end - - def git_command(cmd, options = {}) - root = rails_env.root - mkdir_p "#{root}/vendor/plugins" - base_cmd = "git #{cmd} --depth 1 #{uri} \"#{root}/vendor/plugins/#{name}\"" - puts base_cmd if $verbose - puts "removing: #{root}/vendor/plugins/#{name}/.git" - system(base_cmd) - rm_rf "#{root}/vendor/plugins/#{name}/.git" - end def guess_name(url) @name = File.basename(url) @@ -756,8 +773,8 @@ module Commands "Suppresses the output from installation.", "Ignored if -v is passed (./script/plugin -v install ...)") { |v| @options[:quiet] = true } o.on( "-r REVISION", "--revision REVISION", - "Checks out the given revision from subversion.", - "Ignored if subversion is not used.") { |v| @options[:revision] = v } + "Checks out the given revision from subversion or git.", + "Ignored if subversion/git is not used.") { |v| @options[:revision] = v } o.on( "-f", "--force", "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true } o.separator "" -- cgit v1.2.3 From 0176e6adb388998414083e99523de318d3b8ca49 Mon Sep 17 00:00:00 2001 From: "Sebastian A. Espindola" Date: Tue, 8 Jul 2008 01:14:11 -0300 Subject: Added db:charset support to PostgreSQL. [#556 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/tasks/databases.rake | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 87934c295e..5ec712a02d 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -141,6 +141,9 @@ namespace :db do when 'mysql' ActiveRecord::Base.establish_connection(config) puts ActiveRecord::Base.connection.charset + when 'postgresql' + ActiveRecord::Base.establish_connection(config) + puts ActiveRecord::Base.connection.encoding else puts 'sorry, your database adapter is not supported yet, feel free to submit a patch' end -- cgit v1.2.3 From b337ab0221085ab1a941d87f06eb4904b5852c82 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 15 Jul 2008 21:07:25 +0100 Subject: Move performance test helper settings to railties --- railties/lib/performance_test_help.rb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 railties/lib/performance_test_help.rb (limited to 'railties/lib') diff --git a/railties/lib/performance_test_help.rb b/railties/lib/performance_test_help.rb new file mode 100644 index 0000000000..a5e52a7acb --- /dev/null +++ b/railties/lib/performance_test_help.rb @@ -0,0 +1,6 @@ +require 'action_controller/performance_test' + +ActionController::Base.perform_caching = true +ActionView::Base.cache_template_loading = true +ActiveSupport::Dependencies.mechanism = :require +Rails.logger.level = ActiveSupport::BufferedLogger::INFO -- cgit v1.2.3 From 1edb5c85b58653a6fdc73ae1c6c63e317b466b27 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 15 Jul 2008 15:50:37 -0700 Subject: Give more info on missing gems and abort instead of printing a warning. App can begin in incomplete state otherwise. --- railties/lib/initializer.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 18bcf69d69..7808d88d92 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -266,11 +266,16 @@ module Rails @gems_dependencies_loaded = false # don't print if the gems rake tasks are being run unless $rails_gem_installer - puts %{These gems that this application depends on are missing:} - unloaded_gems.each do |gem| - puts " - #{gem.name}" - end - puts %{Run "rake gems:install" to install them.} + abort <<-end_error +Missing these required gems: + #{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "} + +You're running: + ruby #{Gem.ruby_version} at #{Gem.ruby} + rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '} + +Run `rake gems:install` to install the missing gems. + end_error end else @gems_dependencies_loaded = true -- cgit v1.2.3 From 83e29b9773ac113ceacb1e36c2f333d692de2573 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Jul 2008 22:51:16 -0500 Subject: Removed config.action_view.cache_template_loading, use config.cache_classes instead --- railties/lib/initializer.rb | 1 + railties/lib/performance_test_help.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 7808d88d92..0b052e1fda 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -414,6 +414,7 @@ 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 + ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes ActionMailer::Base.template_root ||= configuration.view_path if configuration.frameworks.include?(:action_mailer) ActionController::Base.view_paths = [configuration.view_path] if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty? end diff --git a/railties/lib/performance_test_help.rb b/railties/lib/performance_test_help.rb index a5e52a7acb..5148b4ab77 100644 --- a/railties/lib/performance_test_help.rb +++ b/railties/lib/performance_test_help.rb @@ -1,6 +1,5 @@ require 'action_controller/performance_test' ActionController::Base.perform_caching = true -ActionView::Base.cache_template_loading = true ActiveSupport::Dependencies.mechanism = :require Rails.logger.level = ActiveSupport::BufferedLogger::INFO -- cgit v1.2.3 From fea5b6fd41f7d667fe637c9e9e31b51489ee5a50 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Jul 2008 22:57:20 -0500 Subject: ActionMailer and ActionView can share the same view path cache --- railties/lib/initializer.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 0b052e1fda..b9e890a3e4 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -415,8 +415,10 @@ Run `rake gems:install` to install the missing gems. # set to use Configuration#view_path. def initialize_framework_views ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes - ActionMailer::Base.template_root ||= configuration.view_path if configuration.frameworks.include?(:action_mailer) - ActionController::Base.view_paths = [configuration.view_path] if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty? + view_path = ActionView::PathSet::Path.new(configuration.view_path) + + 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 # If Action Controller is not one of the loaded frameworks (Configuration#frameworks) -- cgit v1.2.3 From 8b933517ea750e400f0c7dea29c06de0915cd726 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 05:20:29 +0100 Subject: Add config.ru to rails app generator --- .../lib/rails_generator/generators/applications/app/app_generator.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 80e8eabfd3..98fe163455 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -46,6 +46,7 @@ class AppGenerator < Rails::Generator::Base # Root m.file "fresh_rakefile", "Rakefile" m.file "README", "README" + m.file "config.ru", "config.ru" # Application m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest } -- cgit v1.2.3 From 0432d151647f2178ddee79979827d552447c251f Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 13:00:36 +0100 Subject: Merge with docrails. --- railties/lib/commands/process/spawner.rb | 4 ++-- railties/lib/initializer.rb | 4 ++-- .../rails_generator/generators/components/scaffold/USAGE | 14 +++++++++----- railties/lib/rails_generator/scripts.rb | 2 +- railties/lib/rails_generator/scripts/destroy.rb | 13 ++++++------- railties/lib/rails_generator/secret_key_generator.rb | 2 +- 6 files changed, 21 insertions(+), 18 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/process/spawner.rb b/railties/lib/commands/process/spawner.rb index fd09daa55b..dc0008698a 100644 --- a/railties/lib/commands/process/spawner.rb +++ b/railties/lib/commands/process/spawner.rb @@ -66,9 +66,9 @@ class MongrelSpawner < Spawner "-l #{OPTIONS[:rails_root]}/log/mongrel.log" # Add prefix functionality to spawner's call to mongrel_rails - # Digging through monrel's project subversion server, the earliest + # Digging through mongrel's project subversion server, the earliest # Tag that has prefix implemented in the bin/mongrel_rails file - # is 0.3.15 which also happens to be the earilest tag listed. + # is 0.3.15 which also happens to be the earliest tag listed. # References: http://mongrel.rubyforge.org/svn/tags if Mongrel::Const::MONGREL_VERSION.to_f >=0.3 && !OPTIONS[:prefix].nil? cmd = cmd + " --prefix #{OPTIONS[:prefix]}" diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b9e890a3e4..b8b071d4c9 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -98,7 +98,7 @@ module Rails # Rails::Initializer.run(:set_load_path) # # This is useful if you only want the load path initialized, without - # incuring the overhead of completely loading the entire environment. + # incurring the overhead of completely loading the entire environment. def self.run(command = :process, configuration = Configuration.new) yield configuration if block_given? initializer = new configuration @@ -531,7 +531,7 @@ Run `rake gems:install` to install the missing gems. # A stub for setting options on ActiveRecord::Base. attr_accessor :active_record - # A stub for setting options on ActiveRecord::Base. + # A stub for setting options on ActiveResource::Base. attr_accessor :active_resource # A stub for setting options on ActiveSupport. diff --git a/railties/lib/rails_generator/generators/components/scaffold/USAGE b/railties/lib/rails_generator/generators/components/scaffold/USAGE index a0e4baea08..810aea16f1 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/USAGE +++ b/railties/lib/rails_generator/generators/components/scaffold/USAGE @@ -1,10 +1,11 @@ Description: Scaffolds an entire resource, from model and migration to controller and views, along with a full test suite. The resource is ready to use as a - starting point for your restful, resource-oriented application. + starting point for your RESTful, resource-oriented application. - Pass the name of the model, either CamelCased or under_scored, as the first - argument, and an optional list of attribute pairs. + Pass the name of the model (in singular form), either CamelCased or + under_scored, as the first argument, and an optional list of attribute + pairs. Attribute pairs are column_name:sql_type arguments specifying the model's attributes. Timestamps are added by default, so you don't have to @@ -13,13 +14,16 @@ Description: You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the resource immediately. - For example, `scaffold post title:string body:text published:boolean` + For example, 'scaffold post title:string body:text published:boolean' gives you a model with those three attributes, a controller that handles the create/show/update/destroy, forms to create and edit your posts, and an index that lists them all, as well as a map.resources :posts declaration in config/routes.rb. + If you want to remove all the generated files, run + 'script/destroy scaffold ModelName'. + Examples: - `./script/generate scaffold post` # no attributes, view will be anemic + `./script/generate scaffold post` `./script/generate scaffold post title:string body:text published:boolean` `./script/generate scaffold purchase order_id:integer amount:decimal` diff --git a/railties/lib/rails_generator/scripts.rb b/railties/lib/rails_generator/scripts.rb index f857f68de4..9b1a99838a 100644 --- a/railties/lib/rails_generator/scripts.rb +++ b/railties/lib/rails_generator/scripts.rb @@ -45,7 +45,7 @@ module Rails usage = "\nInstalled Generators\n" Rails::Generator::Base.sources.inject([]) do |mem, source| # Using an association list instead of a hash to preserve order, - # for esthetic reasons more than anything else. + # for aesthetic reasons more than anything else. label = source.label.to_s.capitalize pair = mem.assoc(label) mem << (pair = [label, []]) if pair.nil? diff --git a/railties/lib/rails_generator/scripts/destroy.rb b/railties/lib/rails_generator/scripts/destroy.rb index 4fcbc3e0df..a7c2a14751 100644 --- a/railties/lib/rails_generator/scripts/destroy.rb +++ b/railties/lib/rails_generator/scripts/destroy.rb @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../scripts' module Rails::Generator::Scripts class Destroy < Base mandatory_options :command => :destroy - + protected def usage_message usage = "\nInstalled Generators\n" @@ -15,14 +15,13 @@ module Rails::Generator::Scripts usage << < Date: Thu, 17 Jul 2008 02:50:29 +0100 Subject: Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp. [#446 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/rails_generator/commands.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index d258aeaa0a..59af7308fe 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -57,6 +57,17 @@ module Rails end protected + def current_migration_number + Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path| + n = File.basename(file_path).split('_', 2).first.to_i + if n > max then n else max end + end + end + + def next_migration_number + current_migration_number + 1 + end + def migration_directory(relative_path) directory(@migration_directory = relative_path) end @@ -70,7 +81,11 @@ module Rails end def next_migration_string(padding = 3) - Time.now.utc.strftime("%Y%m%d%H%M%S") + if ActiveRecord::Base.timestamped_migrations + Time.now.utc.strftime("%Y%m%d%H%M%S") + else + "%.#{padding}d" % next_migration_number + end end def gsub_file(relative_destination, regexp, *args, &block) -- cgit v1.2.3 From e0d7bace4ecb9152fac112e809af521e36fbc6a5 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Jul 2008 11:42:27 -0500 Subject: Prefer Mongrel over Thin [#658 state:resolved] --- railties/lib/commands/server.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index 7306c248fb..15f417b5be 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -23,10 +23,10 @@ server = case ARGV.first when "lighttpd", "mongrel", "new_mongrel", "webrick", "thin" ARGV.shift else - if defined?(Thin) - "thin" - elsif defined?(Mongrel) + if defined?(Mongrel) "mongrel" + elsif defined?(Thin) + "thin" elsif RUBY_PLATFORM !~ /(:?mswin|mingw)/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI) "lighttpd" else -- cgit v1.2.3 From 3bd34b6ffe017dd81fd26743aab052fc4324eb0f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 14 Jun 2008 16:24:23 -0500 Subject: Preload application classes. Uses same strategy as phusion passenger. --- railties/lib/initializer.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b8b071d4c9..3be95de8d3 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -168,6 +168,9 @@ module Rails # Observers are loaded after plugins in case Observers or observed models are modified by plugins. load_observers + # load application classes + load_application_classes + # Flag initialized Rails.initialized = true end @@ -330,6 +333,14 @@ Run `rake gems:install` to install the missing gems. end end + def load_application_classes + require_dependency 'application' + + Dir.glob('app/{models,controllers,helpers}/*.rb').each do |file| + require_dependency file + end + 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+ -- cgit v1.2.3 From 89ec72c2818a592323fe4ec3277638d379f1ac2a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Jul 2008 13:42:34 -0500 Subject: Added configurable eager load paths. Defaults to app/models, app/controllers, and app/helpers --- railties/lib/initializer.rb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 3be95de8d3..828d688475 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -333,11 +333,14 @@ Run `rake gems:install` to install the missing gems. end end + # Eager load application classes def load_application_classes - require_dependency 'application' - - Dir.glob('app/{models,controllers,helpers}/*.rb').each do |file| - require_dependency file + if configuration.cache_classes + configuration.eager_load_paths.each do |load_path| + Dir.glob("#{load_path}/*.rb").each do |file| + require_dependency file + end + end end end @@ -578,6 +581,11 @@ Run `rake gems:install` to install the missing gems. # All elements of this array must also be in +load_paths+. attr_accessor :load_once_paths + # An array of paths from which Rails will eager load on boot if cache + # classes is enabled. All elements of this array must also be in + # +load_paths+. + attr_accessor :eager_load_paths + # The log level to use for the default Rails logger. In production mode, # this defaults to :info. In development mode, it defaults to # :debug. @@ -686,6 +694,7 @@ Run `rake gems:install` to install the missing gems. self.frameworks = default_frameworks self.load_paths = default_load_paths self.load_once_paths = default_load_once_paths + self.eager_load_paths = default_eager_load_paths self.log_path = default_log_path self.log_level = default_log_level self.view_path = default_view_path @@ -826,6 +835,14 @@ Run `rake gems:install` to install the missing gems. [] end + def default_eager_load_paths + %w( + app/models + app/controllers + app/helpers + ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) } + end + def default_log_path File.join(root_path, 'log', "#{environment}.log") end -- cgit v1.2.3 From 92f944818eece9fe4bc62ffb39accdb71ebc32be Mon Sep 17 00:00:00 2001 From: Miles Georgi Date: Sat, 19 Jul 2008 16:04:35 -0700 Subject: Make script/plugin work with svn+ssh urls. [#662 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/commands/plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index 0256090d16..980244a71b 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -907,7 +907,7 @@ class RecursiveHTTPFetcher def ls @urls_to_fetch.collect do |url| - if url =~ /^svn:\/\/.*/ + if url =~ /^svn(\+ssh)?:\/\/.*/ `svn ls #{url}`.split("\n").map {|entry| "/#{entry}"} rescue nil else open(url) do |stream| -- cgit v1.2.3 From 97a954bf1dd05e79a873bffc94fcf5420b807371 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 23 Jul 2008 10:41:28 -0500 Subject: Load view path cache after plugins and gems. --- railties/lib/initializer.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 828d688475..97bb81a3c8 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -168,6 +168,9 @@ module Rails # Observers are loaded after plugins in case Observers or observed models are modified by plugins. load_observers + # Load view path cache + load_view_paths + # load application classes load_application_classes @@ -333,6 +336,12 @@ Run `rake gems:install` to install the missing gems. end end + def load_view_paths + ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes + ActionMailer::Base.template_root.load + ActionController::Base.view_paths.load + end + # Eager load application classes def load_application_classes if configuration.cache_classes @@ -428,9 +437,7 @@ 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 - ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes - view_path = ActionView::PathSet::Path.new(configuration.view_path) - + 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 -- cgit v1.2.3 From 3fd9036fc554979e951422a79f0f77f061112bdc Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 24 Jul 2008 11:58:26 -0500 Subject: Added config.dependency_loading to enable or disable the dependency loader after initialization --- railties/lib/initializer.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 97bb81a3c8..44863ab026 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -171,9 +171,12 @@ module Rails # Load view path cache load_view_paths - # load application classes + # Load application classes load_application_classes + # Disable dependency loading during request cycle + disable_dependency_loading + # Flag initialized Rails.initialized = true end @@ -525,6 +528,12 @@ Run `rake gems:install` to install the missing gems. Dispatcher.define_dispatcher_callbacks(configuration.cache_classes) Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch end + + def disable_dependency_loading + if configuration.cache_classes && !configuration.dependency_loading + ActiveSupport::Dependencies.unhook! + end + end end # The Configuration class holds all the parameters for the Initializer and @@ -659,6 +668,17 @@ Run `rake gems:install` to install the missing gems. !!@reload_plugins end + # Enables or disables dependency loading during the request cycle. Setting + # dependency_loading to true will allow new classes to be loaded + # during a request. Setting it to false will disable this behavior. + # + # Those who want to run in a threaded environment should disable this + # option and eager load or require all there classes on initialization. + # + # If cache_classes is disabled, dependency loaded will always be + # on. + attr_accessor :dependency_loading + # An array of gems that this rails application depends on. Rails will automatically load # these gems during installation, and allow you to install any missing gems with: # @@ -707,6 +727,7 @@ Run `rake gems:install` to install the missing gems. self.view_path = default_view_path self.controller_paths = default_controller_paths self.cache_classes = default_cache_classes + self.dependency_loading = default_dependency_loading self.whiny_nils = default_whiny_nils self.plugins = default_plugins self.plugin_paths = default_plugin_paths @@ -876,8 +897,8 @@ Run `rake gems:install` to install the missing gems. paths end - def default_dependency_mechanism - :load + def default_dependency_loading + true end def default_cache_classes -- cgit v1.2.3 From 11fdcf88c2aea72ec84c5d4ab05986f5d35a9a81 Mon Sep 17 00:00:00 2001 From: Sam Granieri Date: Thu, 24 Jul 2008 13:51:54 -0500 Subject: Check for ActionMailer and ActionController before attempting to eager load their view paths Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 44863ab026..32411e8928 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -341,8 +341,8 @@ Run `rake gems:install` to install the missing gems. def load_view_paths ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes - ActionMailer::Base.template_root.load - ActionController::Base.view_paths.load + ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) + ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) end # Eager load application classes -- cgit v1.2.3 From d9452d3ab3063c5e96dfd80cf6056c49192081b3 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Tue, 29 Jul 2008 20:01:25 +0200 Subject: Remove incomplete non-blocking logger functionality --- 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 32411e8928..782fbebec2 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -408,7 +408,6 @@ Run `rake gems:install` to install the missing gems. logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase) if configuration.environment == "production" logger.auto_flushing = false - logger.set_non_blocking_io end rescue StandardError => e logger = ActiveSupport::BufferedLogger.new(STDERR) -- cgit v1.2.3 From c8e80f6389b45134c0514dde6736488cf5507765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 30 Jul 2008 01:41:51 -0700 Subject: Initializer skips prepare_dispatcher if Action Controller isn't in use. [#721 state:resolved] --- railties/lib/initializer.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 782fbebec2..8a7461abf5 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -523,6 +523,7 @@ Run `rake gems:install` to install the missing gems. end def prepare_dispatcher + return unless configuration.frameworks.include?(:action_controller) require 'dispatcher' unless defined?(::Dispatcher) Dispatcher.define_dispatcher_callbacks(configuration.cache_classes) Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch -- cgit v1.2.3 From c4038764d2b4c05178cceb22066e0ece59fe49d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 30 Jul 2008 01:49:49 -0700 Subject: Initializer requires ERB explicitly instead of assuming Action Pack loaded it. [#722 state:resolved] --- railties/lib/initializer.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 8a7461abf5..44c24e85f9 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -767,6 +767,7 @@ Run `rake gems:install` to install the missing gems. # contents of the file are processed via ERB before being sent through # YAML::load. def database_configuration + require 'erb' YAML::load(ERB.new(IO.read(database_configuration_file)).result) end -- cgit v1.2.3 From f64bd2ca85595f94cbbe809f51a52cdb9b68af19 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Thu, 31 Jul 2008 09:45:17 +0200 Subject: Ensure dbconsole includes the -p parameter to mysql as intended --- railties/lib/commands/dbconsole.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/commands/dbconsole.rb b/railties/lib/commands/dbconsole.rb index 17acb7b68f..442526ae32 100644 --- a/railties/lib/commands/dbconsole.rb +++ b/railties/lib/commands/dbconsole.rb @@ -41,6 +41,8 @@ when "mysql" if config['password'] && include_password args << "--password=#{config['password']}" + elsif config['password'] && !config['password'].empty? + args << "-p" end args << config['database'] -- cgit v1.2.3 From 030d5854adcf35e6620d667a93a922f5d91725d8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 31 Jul 2008 13:42:28 -0500 Subject: Turn cache_classes on by default [#645 state:resolved] --- railties/lib/initializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 44c24e85f9..88341b9d73 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -903,7 +903,7 @@ Run `rake gems:install` to install the missing gems. end def default_cache_classes - false + true end def default_whiny_nils -- cgit v1.2.3 From 656f0e7c6c9a305abaf9f9b7fb80479b6f94efce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= Date: Thu, 31 Jul 2008 16:36:23 -0500 Subject: Fix file permissions Signed-off-by: Joshua Peek --- railties/lib/commands/ncgi/listener | 0 railties/lib/commands/ncgi/tracker | 0 .../lib/rails_generator/generators/components/plugin/templates/Rakefile | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 railties/lib/commands/ncgi/listener mode change 100644 => 100755 railties/lib/commands/ncgi/tracker mode change 100755 => 100644 railties/lib/rails_generator/generators/components/plugin/templates/Rakefile (limited to 'railties/lib') diff --git a/railties/lib/commands/ncgi/listener b/railties/lib/commands/ncgi/listener old mode 100644 new mode 100755 diff --git a/railties/lib/commands/ncgi/tracker b/railties/lib/commands/ncgi/tracker old mode 100644 new mode 100755 diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/Rakefile b/railties/lib/rails_generator/generators/components/plugin/templates/Rakefile old mode 100755 new mode 100644 -- cgit v1.2.3 From 0b9bfbdebf402f4a149359a069dbeb05ea989b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= Date: Thu, 31 Jul 2008 16:39:48 -0500 Subject: Use "/usr/bin/env ruby" instead of "/usr/local/bin/ruby" Signed-off-by: Joshua Peek --- railties/lib/commands/ncgi/listener | 4 ++-- railties/lib/commands/ncgi/tracker | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/ncgi/listener b/railties/lib/commands/ncgi/listener index 421c453f23..7079ef78a6 100755 --- a/railties/lib/commands/ncgi/listener +++ b/railties/lib/commands/ncgi/listener @@ -1,4 +1,4 @@ -#!/usr/local/bin/ruby +#!/usr/bin/env ruby require 'stringio' require 'fileutils' @@ -83,4 +83,4 @@ end socket_path = ARGV.shift timeout = (ARGV.shift || 90).to_i -Listener.new(timeout, socket_path) \ No newline at end of file +Listener.new(timeout, socket_path) diff --git a/railties/lib/commands/ncgi/tracker b/railties/lib/commands/ncgi/tracker index 859c9fa0e0..4ca12d779b 100755 --- a/railties/lib/commands/ncgi/tracker +++ b/railties/lib/commands/ncgi/tracker @@ -1,4 +1,4 @@ -#!/usr/local/bin/ruby +#!/usr/bin/env ruby require 'drb' require 'thread' @@ -66,4 +66,4 @@ end socket_path = ARGV.shift instances = ARGV.shift.to_i t = Tracker.new(instances, socket_path) -t.background(ARGV.first ? ARGV.shift.to_i : 90) \ No newline at end of file +t.background(ARGV.first ? ARGV.shift.to_i : 90) -- cgit v1.2.3 From a540725f0d3439ea3b0f938d04ceed87d3690d9d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 31 Jul 2008 16:35:17 -0700 Subject: load_application_classes requires files relative to the load path and without .rb extension, including .rb files in subdirectories --- railties/lib/initializer.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 44c24e85f9..611e348acb 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -349,8 +349,9 @@ Run `rake gems:install` to install the missing gems. def load_application_classes if configuration.cache_classes configuration.eager_load_paths.each do |load_path| - Dir.glob("#{load_path}/*.rb").each do |file| - require_dependency file + matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/ + Dir.glob("#{load_path}/**/*.rb").each do |file| + require_dependency file.sub(matcher, '\1') end end end -- cgit v1.2.3 From 43334d63844da05f2cde53c4f77c829e582163be Mon Sep 17 00:00:00 2001 From: Dave Rothlisberger Date: Mon, 4 Aug 2008 14:48:47 -0500 Subject: Corrected the command-line help text for script/dbconsole. --- railties/lib/commands/dbconsole.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/dbconsole.rb b/railties/lib/commands/dbconsole.rb index 442526ae32..e0a2abe73d 100644 --- a/railties/lib/commands/dbconsole.rb +++ b/railties/lib/commands/dbconsole.rb @@ -6,7 +6,7 @@ include_password = false OptionParser.new do |opt| opt.banner = "Usage: dbconsole [options] [environment]" - opt.on("-p", "--include-password", "Automatically provide the database from database.yml") do |v| + opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v| include_password = true end opt.parse!(ARGV) -- cgit v1.2.3