[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to maintain App config data?

Nate Wiger

10/24/2006 6:32:00 PM

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



5 Answers

poopdeville

10/24/2006 7:06:00 PM

0


Nate Wiger 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
>

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/aba412...

Joel VanderWerf

10/24/2006 7:18:00 PM

0

Nate Wiger 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
>
>
> 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/pr...

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

khaines

10/24/2006 7:19:00 PM

0

Nate Wiger

10/24/2006 8:56:00 PM

0

poopdeville@gmail.com wrote:
> Nate Wiger 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
>
> 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/aba412...

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

poopdeville

10/25/2006 7:07:00 PM

0


Nate Wiger wrote:
> poopdeville@gmail.com wrote:
> > Nate Wiger 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
> >
> > 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/aba412...
>
> 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