I'm using Merb and DataMapper with a MySQL db. I want to access the database name, user, and password from a Rake task for my Merb app. I guess I could YAML.load()
the the database.yml, but that seems ugly. Any ideas?
Asked
Active
Viewed 440 times
0

Jim Puls
- 79,175
- 10
- 73
- 78

nicholaides
- 19,211
- 12
- 66
- 82
1 Answers
1
desc "outputs database connection parameters"
task :db_conn => :merb_env do |t|
puts "Username: #{DataMapper.repository.adapter.uri.user}"
puts "Password: #{DataMapper.repository.adapter.uri.password}"
puts "Database: #{DataMapper.repository.adapter.uri.path.split('/').last}"
end
The interesting part there is the => :merb_env
bit. That ensures that the "merb_env" task has executed before your task does. This simply loads up the Merb environment, at which point you can proceed to inspect its configuration.

Greg Campbell
- 15,182
- 3
- 44
- 45