Skip to content

Instantly share code, notes, and snippets.

@lachie
Created May 25, 2010 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lachie/412668 to your computer and use it in GitHub Desktop.
Save lachie/412668 to your computer and use it in GitHub Desktop.
rake_app = Rake::Application.new
rake_app.collect_tasks
if rake_app.top_level_tasks.include?('dev')
if Gem.source_index.find_name('bundler', '>=0.9.0').empty?
abort("Please run `gem install bundler` (version >=0.9.0 needed).")
end
sh "bundle check" do |ok,res|
unless ok
puts "bundling..."
sh "bundle install"
end
end
desc "set up and run for development"
task :dev => 'dev:run'
namespace :dev do
task :bundle do
end
def y_n(prompt,true_response='y')
print "#{prompt} "
response = $stdin.gets.chomp
response.blank? || response.downcase.strip == true_response
end
task :rake_dev_config do
require 'yaml'
dev_config = Rails.root+'config/rake_dev.yml'
if dev_config.exist?
@dev_cfg = YAML.load_file(dev_config)
else
loop do
print "enter path to golfo seed sql: "
path = Pathname($stdin.gets.chomp).expand_path
unless path.exist?
puts "path to seed sql '#{path}' doesn't exist"
retry
end
@dev_cfg = { 'golfo_seed_root' => path.to_s }
dev_config.open('w') {|f| f << @dev_cfg.to_yaml}
break
end
end
end
task :db_config do
unless (Rails.root+"config/database.yml").exist?
abort "Please setup database.yml first"
end
end
task :s3_config do
s3 = Rails.root+'config/s3.yml'
if !s3.exist?
puts "stubbing s3.yml -- note you MUST edit this"
FileUtils.cp( Rails.root+'config/s3.yml.eg', s3)
end
end
task :configure => [:db_config,:s3_config,:rake_dev_config]
task :submodules do
sh "git submodule update --init"
end
# choose either:
#
# a fresh db
# or:
#
# seeding production data
task :seed do
#if !y_n("Seed database? (takes some time) [yN]",'n')
# Rake::Task['dev:seed_from_prod'].invoke
#end
end
task :seed_fresh => ['db:create','db:schema:load','db:seed']
task :seed_from_prod => ['db:drop','db:create'] do
cfg = ActiveRecord::Base.configurations[Rails.env]
abort("golfo db must be mysql (was: #{cfg['adapter']})") unless
root = Pathname(@dev_cfg['golfo_seed_root']).expand_path
clean_tables = lambda {|d| d.basename.to_s[/^simple_captcha_data/]}
slurp_tables = lambda {|tables| sh "cat #{tables * ' '} | mysql -u#{cfg['username']} #{"-p#{cfg['password']}" unless cfg['password'].blank?} #{cfg['database']}"}
slurp_tables[ Pathname.glob(root+'*_schema.sql').reject(&clean_tables) ]
slurp_tables[ Pathname.glob(root+'*_data.sql' ).reject(&clean_tables) ]
Rake::Task['db:migrate'].invoke
Rake::Task['db:seed'].invoke
end
task :run => [:submodules,:configure,:environment,:seed] do
[ 3000 ].each {|port|
fork { system "./script/server -p #{port}" }
}
puts ""
puts "**************"
puts "Browse to http://localhost:3000/ to view the site"
puts "Hit ^C to stop"
puts "**************"
Process.waitall
end
end
else
desc "set up and run app in a convenient dev-only way. rake dev *must* be called as a top level task (i.e. as 'rake dev')"
task :dev do
abort "Please run rake dev as 'rake dev'"
end
end
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
# this includes ^
require File.expand_path('../lib/rake_dev',__FILE__)
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment