Skip to content

Instantly share code, notes, and snippets.

@burtlo
Last active December 14, 2015 01:39
Show Gist options
  • Save burtlo/5007941 to your computer and use it in GitHub Desktop.
Save burtlo/5007941 to your computer and use it in GitHub Desktop.
An example of a Rakefile
$:.push('lib')
require 'sales_engine'
def display_load_path
puts "Current `$LOAD_PATH` (or `$:`):"
puts "Load Path: #{$:.join("\n")}"
end
desc "Add TEST directory to the load path"
task :load_path do
display_load_path
# We want to put the test directory on the load path
test_path = File.expand_path('../test', __FILE__)
if $LOAD_PATH.include?(test_path)
puts "---\nTEST DIR is already on the load path\n---\n"
else
puts "---\nAdding TEST DIR to the load path\n---\n"
$LOAD_PATH.unshift(test_path)
end
display_load_path
end
def cleanup
puts "Cleaning Up My Mess"
end
task :environment do
puts "Loading Environment"
SalesEngine.startup
end
task :external do
puts "Loading External Environment"
end
namespace :test do
[ "third", "fourth"].each do |task_name|
desc "Running the #{task_name} task"
task task_name => [ :environment, :external ] do
puts "Running task #{task_name}"
cleanup
end
end
desc "Hey partner fix this for me while I go drink"
task "first" => :environment do
merchant = SalesEngine::Merchant.find_by_id(1)
puts merchant.name
cleanup
end
desc "Hey partner fix this for me while I go drink"
task "second" => [:environment, :external ] do
merchant = SalesEngine::Merchant.find_by_id(2)
puts merchant.name
cleanup
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment