Rake in the context of Rails
From WhyNotWiki
Contents |
[edit] Rake in the context of Rails
[edit] How does Rails find/load its tasks and my tasks?
your_app/Rakefile:
require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/tasks/rails.rb:
1 $VERBOSE = nil
2
3 # Load Rails rakefile extensions
4 Dir["#{File.dirname(__FILE__)}/*.rake"].each { |ext| load ext }
5
6 # Load any custom rakefile extensions
7 Dir["./lib/tasks/**/*.rake"].sort.each { |ext| load ext }
8 Dir["./vendor/plugins/*/tasks/**/*.rake"].sort.each { |ext| load ext }
[edit] test-related tasks
rake test # Test all units and functionals / Test app + shared Glass.net models rake test:functionals # Run tests for functionalsdb:test:prepare rake test:integration # Run tests for integrationdb:test:prepare rake test:plugins # Run tests for pluginsenvironment rake test:recent # Run tests for recentdb:test:prepare rake test:uncommitted # Run tests for uncommitteddb:test:prepare rake test:units # Run tests for unitsdb:test:prepare
[edit] database tasks
...are in /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/tasks/databases.rake
db:migrate, for example, is defined as:
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
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
...which then uses the Migrator class defined here:
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb
class Migrator#:nodoc:
class << self
def migrate(migrations_path, target_version = nil)
Base.connection.initialize_schema_information
case
when target_version.nil?, current_version < target_version
up(migrations_path, target_version)
when current_version > target_version
down(migrations_path, target_version)
when current_version == target_version
return # You're on the right version
end
end
def up(migrations_path, target_version = nil)
self.new(:up, migrations_path, target_version).migrate
end
[Rails dissections (category)]
Categories: Rails dissections | Rails | Ruby | Rake
