Create a gist now

Instantly share code, notes, and snippets.

mongo task for rails ( put this task file as lib/tasks/mongo.rake )
# -*- mode: ruby -*-
include FileUtils::Verbose
@root = File.expand_path( File.dirname(__FILE__) + '/../../' )
namespace :mongo do
desc 'prepare'
task :prepare do
dbpath = "#{@root}/db/mongodb"
mkdir( dbpath ) unless File.exist? dbpath
conf = File.join( @root, 'config', 'mongo_develop.conf.erb' )
if ( not File.exist? conf )
open( conf, 'w' ) { |f|
f.puts <<'EOD'
<% root = File.expand_path( File.dirname(__FILE__) + '/../' ) %>
dbpath = <%= "#{root}/db/mongodb" %>
logpath = <%= "#{root}/log/mongodb.log" %>
EOD
}
puts "created #{conf} ."
end
end
desc 'start mongod'
task :start do
conf = File.join( @root, 'config', 'mongo_develop.conf' )
sh <<EOD
bundle exec erubis #{conf}.erb > #{conf}
mongod -f #{conf}
EOD
end
end
@wtnabe
Owner
wtnabe commented Apr 30, 2012

sample mongo_develop.conf.erb

<% root = File.expand_path( File.dirname(__FILE__) + '/../' ) %>
dbpath  = <%= "#{root}/db/mongodb" %>
logpath = <%= "#{root}/log/mongodb.log" %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment