From: Marnen Laibow-Koser Date: 2009-11-25T02:25:13+09:00 Subject: Re: Where should I put my config file, and how to load it? Ian Bridgeman wrote: > Hello all! > > I have a small app/set of libraries I'm developing at work called > Sweet. I'm distributing it internally as a ruby gem, which is working > nicely. However I rather foolishly put Sweet's yaml config file in its > config/ directory, so now every time the gem gets upgraded, it wipes > out the current settings. Oops! My plan to fix this problem is to > store the config file at ~/.sweetrc, with a global config file at > /etc/sweetrc to fall back to if the home directory one isn't > available. Does this sound like a sensible solution? Only if your gem is meant as an executable application. > Or am I going > mad? > > The second (and more ruby-ish) question I have is: How can I make sure > all my classes have access to the contents of the config file? My > classes all reside within the 'Sweet' module, and ideally I would like > to be able to do something along the lines of > > @data_directory = Sweet::Config['data_directory'] > > in the initialisation method of any of my classes. Previously all of > the code was pretty much in one class, so that class just had a method > to load the yaml, but I'm doing a pretty major refactoring for Sweet > v2. > Put the yaml in the Config object. > Any assistance would be greatly appreciated! > > - Ian :) > > (Instances of the words 'config file' in this email: 4) Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.