aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/tasks')
-rw-r--r--railties/lib/rails/tasks/annotations.rake20
-rw-r--r--railties/lib/rails/tasks/databases.rake469
-rw-r--r--railties/lib/rails/tasks/documentation.rake88
-rw-r--r--railties/lib/rails/tasks/framework.rake133
-rw-r--r--railties/lib/rails/tasks/gems.rake78
-rw-r--r--railties/lib/rails/tasks/log.rake9
-rw-r--r--railties/lib/rails/tasks/middleware.rake7
-rw-r--r--railties/lib/rails/tasks/misc.rake67
-rw-r--r--railties/lib/rails/tasks/routes.rake18
-rw-r--r--railties/lib/rails/tasks/statistics.rake17
-rw-r--r--railties/lib/rails/tasks/testing.rake139
-rw-r--r--railties/lib/rails/tasks/tmp.rake37
12 files changed, 1082 insertions, 0 deletions
diff --git a/railties/lib/rails/tasks/annotations.rake b/railties/lib/rails/tasks/annotations.rake
new file mode 100644
index 0000000000..79973b3145
--- /dev/null
+++ b/railties/lib/rails/tasks/annotations.rake
@@ -0,0 +1,20 @@
+require 'rails/source_annotation_extractor'
+
+desc "Enumerate all annotations"
+task :notes do
+ SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", :tag => true
+end
+
+namespace :notes do
+ ["OPTIMIZE", "FIXME", "TODO"].each do |annotation|
+ desc "Enumerate all #{annotation} annotations"
+ task annotation.downcase.intern do
+ SourceAnnotationExtractor.enumerate annotation
+ end
+ end
+
+ desc "Enumerate a custom annotation, specify with ANNOTATION=WTFHAX"
+ task :custom do
+ SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
+ end
+end \ No newline at end of file
diff --git a/railties/lib/rails/tasks/databases.rake b/railties/lib/rails/tasks/databases.rake
new file mode 100644
index 0000000000..ed015e7a67
--- /dev/null
+++ b/railties/lib/rails/tasks/databases.rake
@@ -0,0 +1,469 @@
+namespace :db do
+ task :load_config => :rails_env do
+ require 'active_record'
+ ActiveRecord::Base.configurations = Rails::Configuration.new.database_configuration
+ end
+
+ namespace :create do
+ desc 'Create all the local databases defined in config/database.yml'
+ task :all => :load_config do
+ ActiveRecord::Base.configurations.each_value do |config|
+ # Skip entries that don't have a database key, such as the first entry here:
+ #
+ # defaults: &defaults
+ # adapter: mysql
+ # username: root
+ # password:
+ # host: localhost
+ #
+ # development:
+ # database: blog_development
+ # <<: *defaults
+ next unless config['database']
+ # Only connect to local databases
+ local_database?(config) { create_database(config) }
+ end
+ end
+ end
+
+ desc 'Create the database defined in config/database.yml for the current RAILS_ENV'
+ task :create => :load_config do
+ create_database(ActiveRecord::Base.configurations[RAILS_ENV])
+ end
+
+ def create_database(config)
+ begin
+ if config['adapter'] =~ /sqlite/
+ if File.exist?(config['database'])
+ $stderr.puts "#{config['database']} already exists"
+ else
+ begin
+ # Create the SQLite database
+ ActiveRecord::Base.establish_connection(config)
+ ActiveRecord::Base.connection
+ rescue
+ $stderr.puts $!, *($!.backtrace)
+ $stderr.puts "Couldn't create database for #{config.inspect}"
+ end
+ end
+ return # Skip the else clause of begin/rescue
+ else
+ ActiveRecord::Base.establish_connection(config)
+ ActiveRecord::Base.connection
+ end
+ rescue
+ case config['adapter']
+ when 'mysql'
+ @charset = ENV['CHARSET'] || 'utf8'
+ @collation = ENV['COLLATION'] || 'utf8_unicode_ci'
+ creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
+ begin
+ ActiveRecord::Base.establish_connection(config.merge('database' => nil))
+ ActiveRecord::Base.connection.create_database(config['database'], creation_options)
+ ActiveRecord::Base.establish_connection(config)
+ rescue Mysql::Error => sqlerr
+ if sqlerr.errno == Mysql::Error::ER_ACCESS_DENIED_ERROR
+ print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
+ root_password = $stdin.gets.strip
+ grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \
+ "TO '#{config['username']}'@'localhost' " \
+ "IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;"
+ ActiveRecord::Base.establish_connection(config.merge(
+ 'database' => nil, 'username' => 'root', 'password' => root_password))
+ ActiveRecord::Base.connection.create_database(config['database'], creation_options)
+ ActiveRecord::Base.connection.execute grant_statement
+ ActiveRecord::Base.establish_connection(config)
+ else
+ $stderr.puts sqlerr.error
+ $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation}"
+ $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset']
+ end
+ end
+ when 'postgresql'
+ @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
+ begin
+ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
+ ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
+ ActiveRecord::Base.establish_connection(config)
+ rescue
+ $stderr.puts $!, *($!.backtrace)
+ $stderr.puts "Couldn't create database for #{config.inspect}"
+ end
+ end
+ else
+ $stderr.puts "#{config['database']} already exists"
+ end
+ end
+
+ namespace :drop do
+ desc 'Drops all the local databases defined in config/database.yml'
+ task :all => :load_config do
+ ActiveRecord::Base.configurations.each_value do |config|
+ # Skip entries that don't have a database key
+ next unless config['database']
+ begin
+ # Only connect to local databases
+ local_database?(config) { drop_database(config) }
+ rescue Exception => e
+ puts "Couldn't drop #{config['database']} : #{e.inspect}"
+ end
+ end
+ end
+ end
+
+ desc 'Drops the database for the current RAILS_ENV'
+ task :drop => :load_config do
+ config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
+ begin
+ drop_database(config)
+ rescue Exception => e
+ puts "Couldn't drop #{config['database']} : #{e.inspect}"
+ end
+ end
+
+ def local_database?(config, &block)
+ if %w( 127.0.0.1 localhost ).include?(config['host']) || config['host'].blank?
+ yield
+ else
+ puts "This task only modifies local databases. #{config['database']} is on a remote host."
+ end
+ end
+
+
+ desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking db:schema:dump. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
+ task :migrate => :environment do
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
+ ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
+ end
+
+ namespace :migrate do
+ desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
+ task :redo => :environment do
+ if ENV["VERSION"]
+ Rake::Task["db:migrate:down"].invoke
+ Rake::Task["db:migrate:up"].invoke
+ else
+ Rake::Task["db:rollback"].invoke
+ Rake::Task["db:migrate"].invoke
+ end
+ end
+
+ desc 'Resets your database using your migrations for the current environment'
+ task :reset => ["db:drop", "db:create", "db:migrate"]
+
+ desc 'Runs the "up" for a given migration VERSION.'
+ task :up => :environment do
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
+ raise "VERSION is required" unless version
+ ActiveRecord::Migrator.run(:up, "db/migrate/", version)
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
+ end
+
+ desc 'Runs the "down" for a given migration VERSION.'
+ task :down => :environment do
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
+ raise "VERSION is required" unless version
+ ActiveRecord::Migrator.run(:down, "db/migrate/", version)
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
+ end
+ end
+
+ desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
+ task :rollback => :environment do
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
+ ActiveRecord::Migrator.rollback('db/migrate/', step)
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
+ end
+
+ desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
+ task :forward => :environment do
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
+ ActiveRecord::Migrator.forward('db/migrate/', step)
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
+ end
+
+ desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
+ task :reset => [ 'db:drop', 'db:setup' ]
+
+ desc "Retrieves the charset for the current environment's database"
+ task :charset => :environment do
+ config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
+ case config['adapter']
+ 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
+ end
+
+ desc "Retrieves the collation for the current environment's database"
+ task :collation => :environment do
+ config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
+ case config['adapter']
+ when 'mysql'
+ ActiveRecord::Base.establish_connection(config)
+ puts ActiveRecord::Base.connection.collation
+ else
+ puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
+ end
+ end
+
+ desc "Retrieves the current schema version number"
+ task :version => :environment do
+ puts "Current version: #{ActiveRecord::Migrator.current_version}"
+ end
+
+ desc "Raises an error if there are pending migrations"
+ task :abort_if_pending_migrations => :environment do
+ if defined? ActiveRecord
+ pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
+
+ if pending_migrations.any?
+ puts "You have #{pending_migrations.size} pending migrations:"
+ pending_migrations.each do |pending_migration|
+ puts ' %4d %s' % [pending_migration.version, pending_migration.name]
+ end
+ abort %{Run "rake db:migrate" to update your database then try again.}
+ end
+ end
+ end
+
+ desc 'Create the database, load the schema, and initialize with the seed data'
+ task :setup => [ 'db:create', 'db:schema:load', 'db:seed' ]
+
+ desc 'Load the seed data from db/seeds.rb'
+ task :seed => :environment do
+ seed_file = File.join(Rails.root, 'db', 'seeds.rb')
+ load(seed_file) if File.exist?(seed_file)
+ 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. 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 = 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|
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
+ end
+ end
+
+ 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"
+
+ label, id = ENV["LABEL"], ENV["ID"]
+ raise "LABEL or ID required" if label.blank? && id.blank?
+
+ puts %Q(The fixture ID for "#{label}" is #{Fixtures.identify(label)}.) if label
+
+ 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)
+
+ if key == label || key_id == id.to_i
+ puts "#{file}: #{key} (#{key_id})"
+ end
+ end
+ end
+ end
+ end
+ end
+
+ namespace :schema 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'] || "#{RAILS_ROOT}/db/schema.rb", "w") do |file|
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
+ end
+ Rake::Task["db:schema:dump"].reenable
+ end
+
+ desc "Load a schema.rb file into the database"
+ task :load => :environment do
+ file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb"
+ if File.exists?(file)
+ load(file)
+ else
+ abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{RAILS_ROOT}/config/environment.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
+ end
+ end
+ end
+
+ namespace :structure do
+ desc "Dump the database structure to a SQL file"
+ task :dump => :environment do
+ abcs = ActiveRecord::Base.configurations
+ case abcs[RAILS_ENV]["adapter"]
+ when "mysql", "oci", "oracle"
+ ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
+ 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"]
+ ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
+ search_path = abcs[RAILS_ENV]["schema_search_path"]
+ unless search_path.blank?
+ search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
+ end
+ `pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}`
+ raise "Error dumping database" if $?.exitstatus == 1
+ when "sqlite", "sqlite3"
+ dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"]
+ `#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql`
+ when "sqlserver"
+ `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
+ `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r`
+ when "firebird"
+ set_firebird_env(abcs[RAILS_ENV])
+ db_string = firebird_db_string(abcs[RAILS_ENV])
+ 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("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
+ end
+ end
+ end
+
+ namespace :test do
+ desc "Recreate the test database from the current schema.rb"
+ task :load => 'db:test:purge' do
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
+ ActiveRecord::Schema.verbose = false
+ Rake::Task["db:schema:load"].invoke
+ end
+
+ desc "Recreate the test database from the current environment's database schema"
+ task :clone => %w(db:schema:dump db:test:load)
+
+ desc "Recreate the test databases from the development structure"
+ task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
+ abcs = ActiveRecord::Base.configurations
+ case abcs["test"]["adapter"]
+ when "mysql"
+ ActiveRecord::Base.establish_connection(:test)
+ ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
+ 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 #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
+ when "sqlite", "sqlite3"
+ dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
+ `#{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("#{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 #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{db_string}"
+ else
+ raise "Task not supported by '#{abcs["test"]["adapter"]}'"
+ end
+ end
+
+ desc "Empty the test database"
+ task :purge => :environment do
+ abcs = ActiveRecord::Base.configurations
+ case abcs["test"]["adapter"]
+ when "mysql"
+ ActiveRecord::Base.establish_connection(:test)
+ ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"], abcs["test"])
+ when "postgresql"
+ ActiveRecord::Base.clear_active_connections!
+ drop_database(abcs['test'])
+ create_database(abcs['test'])
+ when "sqlite","sqlite3"
+ dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
+ File.delete(dbfile) if File.exist?(dbfile)
+ when "sqlserver"
+ dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
+ `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
+ `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
+ when "oci", "oracle"
+ ActiveRecord::Base.establish_connection(:test)
+ ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
+ ActiveRecord::Base.connection.execute(ddl)
+ end
+ when "firebird"
+ ActiveRecord::Base.establish_connection(:test)
+ ActiveRecord::Base.connection.recreate_database!
+ else
+ raise "Task not supported by '#{abcs["test"]["adapter"]}'"
+ end
+ end
+
+ desc 'Check for pending migrations and load the test schema'
+ task :prepare => 'db:abort_if_pending_migrations' do
+ if defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
+ Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:load" }[ActiveRecord::Base.schema_format]].invoke
+ end
+ end
+ end
+
+ namespace :sessions do
+ desc "Creates a sessions migration for use with ActiveRecord::SessionStore"
+ task :create => :environment do
+ raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
+ require 'rails/generators'
+ require 'rails/generators/rails/session_migration/session_migration_generator'
+ Rails::Generators::SessionMigrationGenerator.start [ ENV["MIGRATION"] || "add_sessions_table" ]
+ end
+
+ desc "Clear the sessions table"
+ task :clear => :environment do
+ ActiveRecord::Base.connection.execute "DELETE FROM #{session_table_name}"
+ end
+ end
+end
+
+def drop_database(config)
+ case config['adapter']
+ when 'mysql'
+ ActiveRecord::Base.establish_connection(config)
+ ActiveRecord::Base.connection.drop_database config['database']
+ when /^sqlite/
+ require 'pathname'
+ path = Pathname.new(config['database'])
+ file = path.absolute? ? path.to_s : File.join(RAILS_ROOT, path)
+
+ FileUtils.rm(file)
+ when 'postgresql'
+ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
+ ActiveRecord::Base.connection.drop_database config['database']
+ end
+end
+
+def session_table_name
+ ActiveRecord::SessionStore::Session.table_name
+end
+
+def set_firebird_env(config)
+ ENV["ISC_USER"] = config["username"].to_s if config["username"]
+ ENV["ISC_PASSWORD"] = config["password"].to_s if config["password"]
+end
+
+def firebird_db_string(config)
+ FireRuby::Database.db_string_for(config.symbolize_keys)
+end
diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake
new file mode 100644
index 0000000000..db1939c45f
--- /dev/null
+++ b/railties/lib/rails/tasks/documentation.rake
@@ -0,0 +1,88 @@
+namespace :doc do
+ desc "Generate documentation for the application. Set custom template with TEMPLATE=/path/to/rdoc/template.rb or title with TITLE=\"Custom Title\""
+ Rake::RDocTask.new("app") { |rdoc|
+ rdoc.rdoc_dir = 'doc/app'
+ rdoc.template = ENV['template'] if ENV['template']
+ rdoc.title = ENV['title'] || "Rails Application Documentation"
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.options << '--charset' << 'utf-8'
+ rdoc.rdoc_files.include('doc/README_FOR_APP')
+ rdoc.rdoc_files.include('app/**/*.rb')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+ }
+
+ desc "Generate documentation for the Rails framework"
+ Rake::RDocTask.new("rails") { |rdoc|
+ rdoc.rdoc_dir = 'doc/api'
+ rdoc.template = "#{ENV['template']}.rb" if ENV['template']
+ rdoc.title = "Rails Framework Documentation"
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('vendor/rails/railties/CHANGELOG')
+ rdoc.rdoc_files.include('vendor/rails/railties/MIT-LICENSE')
+ rdoc.rdoc_files.include('vendor/rails/railties/README')
+ rdoc.rdoc_files.include('vendor/rails/railties/lib/{*.rb,commands/*.rb,generators/*.rb}')
+ rdoc.rdoc_files.include('vendor/rails/activerecord/README')
+ rdoc.rdoc_files.include('vendor/rails/activerecord/CHANGELOG')
+ rdoc.rdoc_files.include('vendor/rails/activerecord/lib/active_record/**/*.rb')
+ rdoc.rdoc_files.exclude('vendor/rails/activerecord/lib/active_record/vendor/*')
+ rdoc.rdoc_files.include('vendor/rails/activeresource/README')
+ rdoc.rdoc_files.include('vendor/rails/activeresource/CHANGELOG')
+ rdoc.rdoc_files.include('vendor/rails/activeresource/lib/active_resource.rb')
+ rdoc.rdoc_files.include('vendor/rails/activeresource/lib/active_resource/*')
+ rdoc.rdoc_files.include('vendor/rails/actionpack/README')
+ rdoc.rdoc_files.include('vendor/rails/actionpack/CHANGELOG')
+ rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_controller/**/*.rb')
+ rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_view/**/*.rb')
+ rdoc.rdoc_files.include('vendor/rails/actionmailer/README')
+ rdoc.rdoc_files.include('vendor/rails/actionmailer/CHANGELOG')
+ rdoc.rdoc_files.include('vendor/rails/actionmailer/lib/action_mailer/base.rb')
+ rdoc.rdoc_files.include('vendor/rails/activesupport/README')
+ rdoc.rdoc_files.include('vendor/rails/activesupport/CHANGELOG')
+ rdoc.rdoc_files.include('vendor/rails/activesupport/lib/active_support/**/*.rb')
+ }
+
+ plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) }
+
+ desc "Generate documentation for all installed plugins"
+ task :plugins => plugins.collect { |plugin| "doc:plugins:#{plugin}" }
+
+ desc "Remove plugin documentation"
+ task :clobber_plugins do
+ rm_rf 'doc/plugins' rescue nil
+ end
+
+ desc "Generate Rails guides"
+ task :guides do
+ require File.join(RAILTIES_PATH, "guides/rails_guides")
+ RailsGuides::Generator.new(File.join(RAILS_ROOT, "doc/guides")).generate
+ end
+
+ namespace :plugins do
+ # Define doc tasks for each plugin
+ plugins.each do |plugin|
+ desc "Generate documentation for the #{plugin} plugin"
+ task(plugin => :environment) do
+ plugin_base = "vendor/plugins/#{plugin}"
+ options = []
+ files = Rake::FileList.new
+ options << "-o doc/plugins/#{plugin}"
+ options << "--title '#{plugin.titlecase} Plugin Documentation'"
+ options << '--line-numbers' << '--inline-source'
+ options << '--charset' << 'utf-8'
+ options << '-T html'
+
+ files.include("#{plugin_base}/lib/**/*.rb")
+ if File.exist?("#{plugin_base}/README")
+ files.include("#{plugin_base}/README")
+ options << "--main '#{plugin_base}/README'"
+ end
+ files.include("#{plugin_base}/CHANGELOG") if File.exist?("#{plugin_base}/CHANGELOG")
+
+ options << files.to_s
+
+ sh %(rdoc #{options * ' '})
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake
new file mode 100644
index 0000000000..17e16f26fd
--- /dev/null
+++ b/railties/lib/rails/tasks/framework.rake
@@ -0,0 +1,133 @@
+namespace :rails do
+ namespace :freeze do
+ desc "Lock this application to the current gems (by unpacking them into vendor/rails)"
+ task :gems do
+ deps = %w(actionpack activerecord actionmailer activesupport activeresource)
+ require 'rubygems'
+ require 'rubygems/gem_runner'
+
+ rails = (version = ENV['VERSION']) ?
+ Gem.cache.find_name('rails', "= #{version}").first :
+ Gem.cache.find_name('rails').sort_by { |g| g.version }.last
+
+ version ||= rails.version
+
+ unless rails
+ puts "No rails gem #{version} is installed. Do 'gem list rails' to see what you have available."
+ exit
+ end
+
+ puts "Freezing to the gems for Rails #{rails.version}"
+ rm_rf "vendor/rails"
+ mkdir_p "vendor/rails"
+
+ begin
+ chdir("vendor/rails") do
+ rails.dependencies.select { |g| deps.include? g.name }.each do |g|
+ Gem::GemRunner.new.run(["unpack", g.name, "--version", g.version_requirements.to_s])
+ mv(Dir.glob("#{g.name}*").first, g.name)
+ end
+
+ Gem::GemRunner.new.run(["unpack", "rails", "--version", "=#{version}"])
+ FileUtils.mv(Dir.glob("rails*").first, "railties")
+ end
+ rescue Exception
+ rm_rf "vendor/rails"
+ raise
+ end
+ end
+
+ desc 'Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0'
+ task :edge do
+ require 'open-uri'
+ version = ENV["RELEASE"] || "edge"
+ target = "rails_#{version}.zip"
+ commits = "http://github.com/api/v1/yaml/rails/rails/commits/master"
+ url = "http://dev.rubyonrails.org/archives/#{target}"
+
+ chdir 'vendor' do
+ latest_revision = YAML.load(open(commits))["commits"].first["id"]
+
+ puts "Downloading Rails from #{url}"
+ File.open('rails.zip', 'wb') do |dst|
+ open url do |src|
+ while chunk = src.read(4096)
+ dst << chunk
+ end
+ end
+ end
+
+ puts 'Unpacking Rails'
+ rm_rf 'rails'
+ `unzip rails.zip`
+ %w(rails.zip rails/Rakefile rails/cleanlogs.sh rails/pushgems.rb rails/release.rb).each do |goner|
+ rm_f goner
+ end
+
+ touch "rails/REVISION_#{latest_revision}"
+ end
+
+ puts 'Updating current scripts, javascripts, and configuration settings'
+ Rake::Task['rails:update'].invoke
+ end
+ end
+
+ desc "Unlock this application from freeze of gems or edge and return to a fluid use of system gems"
+ task :unfreeze do
+ rm_rf "vendor/rails"
+ end
+
+ desc "Update both configs, scripts and public/javascripts from Rails"
+ task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller" ]
+
+ desc "Applies the template supplied by LOCATION=/path/to/template"
+ task :template do
+ template = ENV["LOCATION"]
+ template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
+
+ require 'generators'
+ generator = Rails::Generators::App.new [ RAILS_ROOT ], {}, :destination_root => RAILS_ROOT
+ generator.apply template, :verbose => false
+ end
+
+ namespace :update do
+ def invoke_from_app_generator(method)
+ require 'generators'
+ require 'rails/generators/rails/app/app_generator'
+
+ generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
+ :destination_root => RAILS_ROOT
+ generator.invoke(method)
+ end
+
+ desc "Update config/boot.rb from your current rails install"
+ task :configs do
+ invoke_from_app_generator :create_boot_file
+ end
+
+ desc "Update Prototype javascripts from your current rails install"
+ task :javascripts do
+ invoke_from_app_generator :create_prototype_files
+ end
+
+ desc "Generate dispatcher files in RAILS_ROOT/public"
+ task :generate_dispatchers do
+ invoke_from_app_generator :create_dispatch_files
+ end
+
+ desc "Add new scripts to the application script/ directory"
+ task :scripts do
+ invoke_from_app_generator :create_script_files
+ end
+
+ desc "Rename application.rb to application_controller.rb"
+ task :application_controller do
+ old_style = RAILS_ROOT + '/app/controllers/application.rb'
+ new_style = RAILS_ROOT + '/app/controllers/application_controller.rb'
+ if File.exists?(old_style) && !File.exists?(new_style)
+ FileUtils.mv(old_style, new_style)
+ puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary"
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/tasks/gems.rake b/railties/lib/rails/tasks/gems.rake
new file mode 100644
index 0000000000..f1c34c7cca
--- /dev/null
+++ b/railties/lib/rails/tasks/gems.rake
@@ -0,0 +1,78 @@
+desc "List the gems that this rails application depends on"
+task :gems => 'gems:base' do
+ Rails.configuration.gems.each do |gem|
+ print_gem_status(gem)
+ end
+ puts
+ puts "I = Installed"
+ puts "F = Frozen"
+ puts "R = Framework (loaded before rails starts)"
+end
+
+namespace :gems do
+ task :base do
+ $gems_rake_task = true
+ require 'rubygems'
+ require 'rubygems/gem_runner'
+ Rake::Task[:environment].invoke
+ end
+
+ desc "Build any native extensions for unpacked gems"
+ task :build do
+ $gems_build_rake_task = true
+ frozen_gems.each { |gem| gem.build }
+ end
+
+ namespace :build do
+ desc "Force the build of all gems"
+ task :force do
+ $gems_build_rake_task = true
+ frozen_gems.each { |gem| gem.build(:force => true) }
+ end
+ end
+
+ desc "Installs all required gems."
+ task :install => :base do
+ current_gems.each { |gem| gem.install }
+ end
+
+ desc "Unpacks all required gems into vendor/gems."
+ task :unpack => :install do
+ current_gems.each { |gem| gem.unpack }
+ end
+
+ namespace :unpack do
+ desc "Unpacks all required gems and their dependencies into vendor/gems."
+ task :dependencies => :install do
+ current_gems.each { |gem| gem.unpack(:recursive => true) }
+ end
+ end
+
+ desc "Regenerate gem specifications in correct format."
+ task :refresh_specs do
+ frozen_gems(false).each { |gem| gem.refresh }
+ end
+end
+
+def current_gems
+ gems = Rails.configuration.gems
+ gems = gems.select { |gem| gem.name == ENV['GEM'] } unless ENV['GEM'].blank?
+ gems
+end
+
+def frozen_gems(load_specs=true)
+ Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*-*')].map do |gem_dir|
+ Rails::GemDependency.from_directory_name(gem_dir, load_specs)
+ end
+end
+
+def print_gem_status(gem, indent=1)
+ code = case
+ when gem.framework_gem? then 'R'
+ when gem.frozen? then 'F'
+ when gem.installed? then 'I'
+ else ' '
+ end
+ puts " "*(indent-1)+" - [#{code}] #{gem.name} #{gem.requirement.to_s}"
+ gem.dependencies.each { |g| print_gem_status(g, indent+1) }
+end
diff --git a/railties/lib/rails/tasks/log.rake b/railties/lib/rails/tasks/log.rake
new file mode 100644
index 0000000000..6e1334692e
--- /dev/null
+++ b/railties/lib/rails/tasks/log.rake
@@ -0,0 +1,9 @@
+namespace :log do
+ desc "Truncates all *.log files in log/ to zero bytes"
+ task :clear do
+ FileList["log/*.log"].each do |log_file|
+ f = File.open(log_file, "w")
+ f.close
+ end
+ end
+end
diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake
new file mode 100644
index 0000000000..05f159184e
--- /dev/null
+++ b/railties/lib/rails/tasks/middleware.rake
@@ -0,0 +1,7 @@
+desc 'Prints out your Rack middleware stack'
+task :middleware => :environment do
+ ActionController::Dispatcher.middleware.active.each do |middleware|
+ puts "use #{middleware.inspect}"
+ end
+ puts "run ActionController::Dispatcher.new"
+end
diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake
new file mode 100644
index 0000000000..fb2fc31dc1
--- /dev/null
+++ b/railties/lib/rails/tasks/misc.rake
@@ -0,0 +1,67 @@
+task :default => :test
+task :environment do
+ $rails_rake_task = true
+ require(File.join(RAILS_ROOT, 'config', 'environment'))
+end
+
+task :rails_env do
+ unless defined? RAILS_ENV
+ RAILS_ENV = ENV['RAILS_ENV'] ||= 'development'
+ end
+end
+
+desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.'
+task :secret do
+ require 'active_support/secure_random'
+ puts ActiveSupport::SecureRandom.hex(64)
+end
+
+namespace :time do
+ namespace :zones do
+ desc 'Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6'
+ task :all do
+ build_time_zone_list(:all)
+ end
+
+ desc 'Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6'
+ task :us do
+ build_time_zone_list(:us_zones)
+ end
+
+ desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
+ task :local do
+ require 'active_support'
+ require 'active_support/time'
+ jan_offset = Time.now.beginning_of_year.utc_offset
+ jul_offset = Time.now.beginning_of_year.change(:month => 7).utc_offset
+ offset = jan_offset < jul_offset ? jan_offset : jul_offset
+ build_time_zone_list(:all, offset)
+ end
+
+ # to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600
+ def build_time_zone_list(method, offset = ENV['OFFSET'])
+ require 'active_support'
+ require 'active_support/time'
+ if offset
+ offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/)
+ sign = $1 == '-' ? -1 : 1
+ hours, minutes = $2.to_f, $3.to_f
+ ((hours * 3600) + (minutes.to_f * 60)) * sign
+ elsif offset.to_f.abs <= 13
+ offset.to_f * 3600
+ else
+ offset.to_f
+ end
+ end
+ previous_offset = nil
+ ActiveSupport::TimeZone.__send__(method).each do |zone|
+ if offset.nil? || offset == zone.utc_offset
+ puts "\n* UTC #{zone.formatted_offset} *" unless zone.utc_offset == previous_offset
+ puts zone.name
+ previous_offset = zone.utc_offset
+ end
+ end
+ puts "\n"
+ end
+ end
+end
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake
new file mode 100644
index 0000000000..abbf3258c1
--- /dev/null
+++ b/railties/lib/rails/tasks/routes.rake
@@ -0,0 +1,18 @@
+desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
+task :routes => :environment do
+ all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
+ routes = all_routes.collect do |route|
+ name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
+ verb = route.conditions[:method].to_s.upcase
+ segs = route.segments.inject("") { |str,s| str << s.to_s }
+ segs.chop! if segs.length > 1
+ reqs = route.requirements.empty? ? "" : route.requirements.inspect
+ {:name => name, :verb => verb, :segs => segs, :reqs => reqs}
+ end
+ name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
+ verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
+ segs_width = routes.collect {|r| r[:segs]}.collect {|s| s.length}.max
+ routes.each do |r|
+ puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
+ end
+end
diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake
new file mode 100644
index 0000000000..2dcc7bdf9d
--- /dev/null
+++ b/railties/lib/rails/tasks/statistics.rake
@@ -0,0 +1,17 @@
+STATS_DIRECTORIES = [
+ %w(Controllers app/controllers),
+ %w(Helpers app/helpers),
+ %w(Models app/models),
+ %w(Libraries lib/),
+ %w(APIs app/apis),
+ %w(Integration\ tests test/integration),
+ %w(Functional\ tests test/functional),
+ %w(Unit\ tests test/unit)
+
+].collect { |name, dir| [ name, "#{RAILS_ROOT}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
+
+desc "Report code statistics (KLOCs, etc) from the application"
+task :stats do
+ require 'rails/code_statistics'
+ CodeStatistics.new(*STATS_DIRECTORIES).to_s
+end
diff --git a/railties/lib/rails/tasks/testing.rake b/railties/lib/rails/tasks/testing.rake
new file mode 100644
index 0000000000..fd5e52a05b
--- /dev/null
+++ b/railties/lib/rails/tasks/testing.rake
@@ -0,0 +1,139 @@
+TEST_CHANGES_SINCE = Time.now - 600
+
+# Look up tests for recently modified sources.
+def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago)
+ FileList[source_pattern].map do |path|
+ if File.mtime(path) > touched_since
+ tests = []
+ source_dir = File.dirname(path).split("/")
+ source_file = File.basename(path, '.rb')
+
+ # Support subdirs in app/models and app/controllers
+ modified_test_path = source_dir.length > 2 ? "#{test_path}/" << source_dir[1..source_dir.length].join('/') : test_path
+
+ # For modified files in app/ run the tests for it. ex. /test/functional/account_controller.rb
+ test = "#{modified_test_path}/#{source_file}_test.rb"
+ tests.push test if File.exist?(test)
+
+ # For modified files in app, run tests in subdirs too. ex. /test/functional/account/*_test.rb
+ test = "#{modified_test_path}/#{File.basename(path, '.rb').sub("_controller","")}"
+ FileList["#{test}/*_test.rb"].each { |f| tests.push f } if File.exist?(test)
+
+ return tests
+
+ end
+ end.flatten.compact
+end
+
+
+# Recreated here from ActiveSupport because :uncommitted needs it before Rails is available
+module Kernel
+ def silence_stderr
+ old_stderr = STDERR.dup
+ STDERR.reopen(RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'NUL:' : '/dev/null')
+ STDERR.sync = true
+ yield
+ ensure
+ STDERR.reopen(old_stderr)
+ end
+end
+
+desc 'Run all unit, functional and integration tests'
+task :test do
+ errors = %w(test:units test:functionals test:integration).collect do |task|
+ begin
+ Rake::Task[task].invoke
+ nil
+ rescue => e
+ task
+ end
+ end.compact
+ abort "Errors running #{errors.to_sentence(:locale => :en)}!" if errors.any?
+end
+
+namespace :test do
+ Rake::TestTask.new(:recent => "db:test:prepare") do |t|
+ since = TEST_CHANGES_SINCE
+ touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +
+ recent_tests('app/models/**/*.rb', 'test/unit', since) +
+ recent_tests('app/controllers/**/*.rb', 'test/functional', since)
+
+ t.libs << 'test'
+ t.verbose = true
+ t.test_files = touched.uniq
+ end
+ Rake::Task['test:recent'].comment = "Test recent changes"
+
+ Rake::TestTask.new(:uncommitted => "db:test:prepare") do |t|
+ def t.file_list
+ if File.directory?(".svn")
+ changed_since_checkin = silence_stderr { `svn status` }.map { |path| path.chomp[7 .. -1] }
+ elsif File.directory?(".git")
+ changed_since_checkin = silence_stderr { `git ls-files --modified --others` }.map { |path| path.chomp }
+ else
+ abort "Not a Subversion or Git checkout."
+ end
+
+ models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ }
+ controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ }
+
+ unit_tests = models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" }
+ functional_tests = controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" }
+
+ unit_tests.uniq + functional_tests.uniq
+ end
+
+ t.libs << 'test'
+ t.verbose = true
+ end
+ Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)"
+
+ Rake::TestTask.new(:units => "db:test:prepare") do |t|
+ t.libs << "test"
+ t.pattern = 'test/unit/**/*_test.rb'
+ t.verbose = true
+ end
+ Rake::Task['test:units'].comment = "Run the unit tests in test/unit"
+
+ Rake::TestTask.new(:functionals => "db:test:prepare") do |t|
+ t.libs << "test"
+ t.pattern = 'test/functional/**/*_test.rb'
+ t.verbose = true
+ end
+ Rake::Task['test:functionals'].comment = "Run the functional tests in test/functional"
+
+ Rake::TestTask.new(:integration => "db:test:prepare") do |t|
+ t.libs << "test"
+ t.pattern = 'test/integration/**/*_test.rb'
+ t.verbose = true
+ end
+ Rake::Task['test:integration'].comment = "Run the integration tests in test/integration"
+
+ Rake::TestTask.new(:benchmark => 'db:test:prepare') do |t|
+ t.libs << 'test'
+ t.pattern = 'test/performance/**/*_test.rb'
+ t.verbose = true
+ t.options = '-- --benchmark'
+ end
+ Rake::Task['test:benchmark'].comment = 'Benchmark the performance tests'
+
+ Rake::TestTask.new(:profile => 'db:test:prepare') do |t|
+ t.libs << 'test'
+ t.pattern = 'test/performance/**/*_test.rb'
+ t.verbose = true
+ end
+ Rake::Task['test:profile'].comment = 'Profile the performance tests'
+
+ Rake::TestTask.new(:plugins => :environment) do |t|
+ t.libs << "test"
+
+ if ENV['PLUGIN']
+ t.pattern = "vendor/plugins/#{ENV['PLUGIN']}/test/**/*_test.rb"
+ else
+ t.pattern = 'vendor/plugins/*/**/test/**/*_test.rb'
+ end
+
+ t.verbose = true
+ end
+ Rake::Task['test:plugins'].comment = "Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)"
+end
diff --git a/railties/lib/rails/tasks/tmp.rake b/railties/lib/rails/tasks/tmp.rake
new file mode 100644
index 0000000000..fea15058bb
--- /dev/null
+++ b/railties/lib/rails/tasks/tmp.rake
@@ -0,0 +1,37 @@
+namespace :tmp do
+ desc "Clear session, cache, and socket files from tmp/"
+ task :clear => [ "tmp:sessions:clear", "tmp:cache:clear", "tmp:sockets:clear"]
+
+ desc "Creates tmp directories for sessions, cache, sockets, and pids"
+ task :create do
+ FileUtils.mkdir_p(%w( tmp/sessions tmp/cache tmp/sockets tmp/pids ))
+ end
+
+ namespace :sessions do
+ desc "Clears all files in tmp/sessions"
+ task :clear do
+ FileUtils.rm(Dir['tmp/sessions/[^.]*'])
+ end
+ end
+
+ namespace :cache do
+ desc "Clears all files and directories in tmp/cache"
+ task :clear do
+ FileUtils.rm_rf(Dir['tmp/cache/[^.]*'])
+ end
+ end
+
+ namespace :sockets do
+ desc "Clears all files in tmp/sockets"
+ task :clear do
+ FileUtils.rm(Dir['tmp/sockets/[^.]*'])
+ end
+ end
+
+ namespace :pids do
+ desc "Clears all files in tmp/pids"
+ task :clear do
+ FileUtils.rm(Dir['tmp/pids/[^.]*'])
+ end
+ end
+end