How do I return early from a rake task?

A Rake task is basically a block. A block, except lambdas, doesn’t support return but you can skip to the next statement using next which in a rake task has the same effect of using return in a method. task :foo do puts “printed” next puts “never printed” end Or you can move the code … Read more

How to run Rake tasks from within Rake tasks?

If you need the task to behave as a method, how about using an actual method? task :build => [:some_other_tasks] do build end task :build_all do [:debug, :release].each { |t| build t } end def build(type = :debug) # … end If you’d rather stick to rake‘s idioms, here are your possibilities, compiled from past … Read more

Difference between rake db:migrate db:reset and db:schema:load

db:migrate runs (single) migrations that have not run yet. db:create creates the database db:drop deletes the database db:schema:load creates tables and columns within the existing database following schema.rb. This will delete existing data. db:setup does db:create, db:schema:load, db:seed db:reset does db:drop, db:setup db:migrate:reset does db:drop, db:create, db:migrate Typically, you would use db:migrate after having made … Read more

How to pass command line arguments to a rake task

You can specify formal arguments in rake by adding symbol arguments to the task call. For example: require ‘rake’ task :my_task, [:arg1, :arg2] do |t, args| puts “Args were: #{args} of class #{args.class}” puts “arg1 was: ‘#{args[:arg1]}’ of class #{args[:arg1].class}” puts “arg2 was: ‘#{args[:arg2]}’ of class #{args[:arg2].class}” end task :invoke_my_task do Rake.application.invoke_task(“my_task[1, 2]”) end # … Read more