Easy configuration

3 views
Skip to first unread message

Kless

unread,
Sep 23, 2008, 3:20:47 PM9/23/08
to merb
Configatron [1] makes configuring your applications and scripts
incredibly easy. No longer is a there a need to use constants or
global variables.


[1] http://github.com/markbates/configatron/tree/master

Michael Klishin

unread,
Sep 23, 2008, 4:07:33 PM9/23/08
to me...@googlegroups.com
2008/9/23 Kless <jona...@googlemail.com>:

Can you update Merb wiki with some example of how you use that library
with Merb applications? thank you.
--
MK

Kless

unread,
Sep 24, 2008, 1:33:17 PM9/24/08
to merb
This was said me by its author, Mark Bates:

"Configatron can be used anywhere in any ruby application.

All you have to do is require the configatron gem, and then start
setting configuration parameters. I would choose a file in Merb that
you know will only get required at start up time, and put all you
configurations in there. After that you can refer to them any where in
your code."

So, the file where put the configuration would be 'init.rb' (and also
require the gem using 'dependency').


On 23 sep, 21:07, "Michael Klishin" <michael.s.klis...@gmail.com>
wrote:
> 2008/9/23 Kless <jonas....@googlemail.com>:

Kless

unread,
Sep 24, 2008, 4:41:17 PM9/24/08
to merb
I found a application, MerbSettings [1], more apropiated to Merb since
that you can have settings that are scoped to a model.


[1] http://github.com/felix/merb-settings/tree/master

Kless

unread,
Oct 9, 2008, 10:23:03 AM10/9/08
to merb
I've been played with both plugins and I prefer to configatron.
The main problem of MerbSettings is that the settings are saved into a
table (RDBMS) and it isn't as powerfull as the another one.

Configatron is simple and flexible. Lets configure from a hash or from
YAML files. This is great! With a simple YAML file you can change
easily the configuration of your application.

In fact, I think that any Merb developer should see Configatron as a
possible replacement to 'Merb::Config.use'

Kless

unread,
Oct 10, 2008, 8:28:55 AM10/10/08
to merb
I've written a little post about its use in my Merb slice:

http://blog.jonasmelian.com/2008/10/configure-easily-merb-application/

Henrik N

unread,
Nov 28, 2008, 8:58:41 AM11/28/08
to merb
I implemented a very, very simple Settings object for a recent
project: http://gist.github.com/29987

Dale Campbell

unread,
Nov 28, 2008, 9:33:22 PM11/28/08
to merb
Nice, Henrik. This is a very simple and flexible approach to custom
application settings. No external dependencies required.

Dale Campbell

unread,
Nov 29, 2008, 10:55:35 AM11/29/08
to merb
Here's a simple solution I've been using for a while. It loads
settings from 'config/app_config.yml' into a Mash (so you can access
with AppConfig['name'] or AppConfig[:name]). The Mash class
rules. ;)

# config/init.rb
Merb::BootLoader.after_app_loads do
# This will get executed after your app's classes have been loaded.
begin
config_file = File.expand_path(Merb.root + '/config/
app_config.yml')
AppConfig = Mash.new(YAML.load_file(config_file)[Merb.env]) unless
defined? AppConfig
rescue => error
puts 'AppConfig could not be loaded!'
puts error
end
end

# config/app_config.yml
defaults: &defaults
name: Super Awesome Blog
tagline: My super awesome blog and stuff.
email: y...@example.org

development:
<<: *defaults
# Override the defaults.

test:
<<: *defaults
# Override the defaults.

production:
<<: *defaults
# Override the defaults.
tagline: My super awesome blog, in production!

Dale Campbell

unread,
Nov 29, 2008, 11:00:27 AM11/29/08
to merb
Ugh, posting code to Google Groups sucks. Here's a more readable
version:

http://gist.github.com/30253
Reply all
Reply to author
Forward
0 new messages