# How to maintain App config data?

**URL:** <https://www.ruby-forum.com/t/how-to-maintain-app-config-data/73466>\
**Category:** Ruby\
**Created:** [October 24, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/how-to-maintain-app-config-data/73466 "2006-10-24T20:33:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [October 24, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/how-to-maintain-app-config-data/73466/1 "2006-10-24T20:33:40Z")

</div>

I’m writing an app in Rails, but some modules need to work outside of  
Rails. In these classes, I’d like to have a common way to access  
configuration data. Two approaches I though of:

1. Use a Singleton class ala the Logger concept, and have  
a “conf” object floating around that can provide the  
“conf.root\_dir” or whatever

2. Mixin a module that provides a conf() routine, so that  
classes would call conf(‘root\_dir’) / etc

Opinions? In the Perl world, I would use Config::Fast and attach a  
$self-\>{conf} hashref to my classes, which all point to a shared object.

Thanks,  
Nate

---

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [October 24, 2006, 9:11pm UTC](https://www.ruby-forum.com/t/how-to-maintain-app-config-data/73466/2 "2006-10-24T21:11:28Z")

</div>

Nate W. wrote:

> 

The first option is most like the Perl solution. It’s pretty  
straightforward. Something along these lines might work for you,  
though it’s not a singleton class by design:

[http://groups.google.com/group/comp.lang.ruby/msg/aba4124d4d16d6b0](http://groups.google.com/group/comp.lang.ruby/msg/aba4124d4d16d6b0)

---

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [October 24, 2006, 9:21pm UTC](https://www.ruby-forum.com/t/how-to-maintain-app-config-data/73466/3 "2006-10-24T21:21:29Z")

</div>

Nate W. wrote:

> Opinions? In the Perl world, I would use Config::Fast and attach a  
> $self-\>{conf} hashref to my classes, which all point to a shared object.

This was developed for GUI (specifically FXRuby) apps, but would  
probably work with any kind of app:

[http://raa.ruby-lang.org/project/preferences/](http://raa.ruby-lang.org/project/preferences/)

---

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [October 24, 2006, 9:21pm UTC](https://www.ruby-forum.com/t/how-to-maintain-app-config-data/73466/4 "2006-10-24T21:21:30Z")

</div>

On Wed, 25 Oct 2006, Nate W. wrote:

> I’m writing an app in Rails, but some modules need to work outside of Rails.  
> In these classes, I’d like to have a common way to access configuration data.  
> Two approaches I though of:
> 
> 1. Use a Singleton class ala the Logger concept, and have  
> a “conf” object floating around that can provide the  
> “conf.root\_dir” or whatever
> 
> 2. Mixin a module that provides a conf() routine, so that  
> classes would call conf(‘root\_dir’) / etc

In IOWA apps, there is a method, Iowa.config, that has a reference to  
the  
config object for the application.

This lets that config object be accessed by any code anywhere, similar  
to  
your option #1.

Kirk H.

---

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [October 24, 2006, 10:56pm UTC](https://www.ruby-forum.com/t/how-to-maintain-app-config-data/73466/5 "2006-10-24T22:56:56Z")

</div>

removed\_email\_address@domain.invalid wrote:

> straightforward. Something along these lines might work for you,  
> though it’s not a singleton class by design:
> 
> [http://groups.google.com/group/comp.lang.ruby/msg/aba4124d4d16d6b0](http://groups.google.com/group/comp.lang.ruby/msg/aba4124d4d16d6b0)

Awesome, that looks great. I think I’ll tweak it into a Singleton w/o  
the global vars (just method accessors). I’ll post a follow-up if I come  
up with something semi-portable.

-Nate

---

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [October 25, 2006, 9:10pm UTC](https://www.ruby-forum.com/t/how-to-maintain-app-config-data/73466/6 "2006-10-25T21:10:32Z")

</div>

Nate W. wrote:

> > The first option is most like the Perl solution. It’s pretty  
> > straightforward. Something along these lines might work for you,  
> > though it’s not a singleton class by design:
> > 
> > [http://groups.google.com/group/comp.lang.ruby/msg/aba4124d4d16d6b0](http://groups.google.com/group/comp.lang.ruby/msg/aba4124d4d16d6b0)
> 
> Awesome, that looks great. I think I’ll tweak it into a Singleton w/o  
> the global vars (just method accessors). I’ll post a follow-up if I come  
> up with something semi-portable.

Like the comments in there say, we’re deprecating the global vars  
usage. It’s only in there for backwards compatibility until we weed  
them all out and start using the config object everywhere.

'cid 'ooh
