I found myself needing to check the existence of a Postgres database from Ruby, and ended up with the following (ugly) code:
def database_exists
`sudo su postgres -c 'psql -l | grep #{database_name} | wc -l'`.strip.to_i > 0
end
My concern is that not only is this not water-tight, but there must be a function already out there to do this sort of thing.
Can anyone let me know what functions exist in Ruby to do this cleanly ?