Loading configuration files in an OS-agnostic way

Hi,
  I downloaded ruby-google and tried to run the sample code when I noticed that the code was unusable as is, in Windows, because it assumed that the configuration file is named .google_key and Win 2000 Professional atleast does not allow '.' to be the first character of a filename.

KEY = File.open("#{ENV['HOME']}/.google_key") {|kf| kf.readline.chomp}

I made a quick modification just so I could get it working. (Ugly, I know)

KEY =
  begin
    File.open("#{ENV['HOME']}/.google_key") {|kf| kf.readline.chomp}
  rescue
    File.open("#{ENV['HOME']}/~google_key") {|kf| kf.readline.chomp}
  end

What I'd like to know is what is the ruby idiom for choosing configuration files in an OS-agnostic way? (Emacs does this, choosing ~emacs on Win and .emacs on Linux) . Or is this too simple an issue to require an idiom?

thanks,
gavri

···

---------------------------------------------------------------------------------------------
This message, including any attachments, contains confidential information intended for a specific individual and purpose, and is intended for the addressee only. Any unauthorized disclosure, use, dissemination, copying, or distribution of this message or any of its attachments or the information contained in this e-mail, or the taking of any action based on it, is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by return e-mail and delete this message.

Are you sure? That strikes me as odd, and Windows XP (which is essentially 2000+goodies anyway) is fine with it. Most systems I have encountered which are attempting to be agnostic use a period regardless (or a tilde, as you have).

Pete

···

On 17 Dec 2004, at 07:52, Gavri Savio Fernandez wrote:

unusable as is, in Windows, because it assumed that the configuration file is named .google_key and Win 2000 Professional atleast does not allow '.' to be the first character of a filename.

Peter Cooper schrieb:

···

On 17 Dec 2004, at 07:52, Gavri Savio Fernandez wrote:

unusable as is, in Windows, because it assumed that the configuration file is named .google_key and Win 2000 Professional atleast does not allow '.' to be the first character of a filename.

Are you sure? That strikes me as odd, and Windows XP (which is essentially 2000+goodies anyway) is fine with it. Most systems I have encountered which are attempting to be agnostic use a period regardless (or a tilde, as you have).

At least on Win 2000, you can't create such a file in the Windows Explorer, but you sure can in Ruby:

   File.open ".google_key", "w" do |out| out.puts "# config" end

Regards,
Pit