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:
Use a Singleton class ala the Logger concept, and have
a “conf” object floating around that can provide the
“conf.root_dir” or whatever
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.
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:
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:
Use a Singleton class ala the Logger concept, and have
a “conf” object floating around that can provide the
“conf.root_dir” or whatever
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.
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.
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:
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.