Forum: Ruby on Rails Why is configuration in YAML and not Ruby?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A84d51d60791f8e0fb6d27a8a8b2a96e?d=identicon&s=25 Neil Wilson (neilw)
on 2006-02-19 23:02
On thing that has struck me about dynamic languages is that you don't
need configuration files at all. You can just alter the definitions
directly in the Ruby code.

So if everything is Ruby and configuration files are frowned upon, why
does Rails store the database connectors in a config file 'database.yml'

What's wrong with a 'database.rb' containing

development = { :adapter => 'mysql', :database => 'depot_development',
etc... }

plus whatever syntactic sugar is required to get the thing in the right
place.

I know it doesn't matter. I'm just trying to understand the logic or
history behind it. At the moment it seems a bit of an anathema in an
otherwise elegant structure.

Regards

NeilW
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-02-20 02:01
(Received via mailing list)
On 2/19/06, Neil Wilson <aldursys@gmail.com> wrote:
> etc... }
>
> plus whatever syntactic sugar is required to get the thing in the right
> place.
>
> I know it doesn't matter. I'm just trying to understand the logic or
> history behind it. At the moment it seems a bit of an anathema in an
> otherwise elegant structure.
>

The YAML file is just the Ruby hash you put in you rmessage, dumped
out to a config file.  YAML is nice because it's easy to dump and
reload.
One problem with 'database.rb' is that it would be a little harder to
make a change and save it.
Stated another way, .rb files are meant to be edited by people, .yml
files can easily be edited by people or by code.
When the YAML file is read in, it becomes a regular old Hash.
A52b0e1c5d982f2512a03c5dbfd033d6?d=identicon&s=25 Dick Davies (Guest)
on 2006-02-21 00:22
(Received via mailing list)
On 20/02/06, Wilson Bilkovich <wilsonb@gmail.com> wrote:

> The YAML file is just the Ruby hash you put in your message, dumped
> out to a config file.  YAML is nice because it's easy to dump and
> reload.

Yes, but it's also awful. *Lots* of people have trouble with the
'two leading spaces, not tabs' issue, for example. And how often do
you reload (or
dynamically write) your rails config hash?

A Ruby hash isn't much harder to write out than a YAML hash
(we're not talking Java and XML here), and you'd have a lot more
flexibility in doing things that (e.g.) yaml aliases are currently used
for if
you just had a class method to populate the config hash.

I'd suggest it's YAML based for historical reasons  -
otherwise we'd be looking at  routes.yml etc.

--
Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/
90a73d9875462aaa9fab2feffafbffe7?d=identicon&s=25 Ben Bleything (Guest)
on 2006-02-21 01:45
(Received via mailing list)
On Mon, Feb 20, 2006, Dick Davies wrote:
> I'd suggest it's YAML based for historical reasons  -
> otherwise we'd be looking at  routes.yml etc.

Except that routes can contain a bunch of logic, which you can't put
into YAML.

Configuration files are very rarely written in the same language as the
app.  Part of the idea is that you don't want people to have to know the
language to configure your application.  I'm sure there are other
reasons, that's just the first one that comes to mind.

Ben
6edd67c92a1dab5eb23fed79f3c18564?d=identicon&s=25 David Heinemeier Hansson (Guest)
on 2006-02-21 05:16
(Received via mailing list)
> Configuration files are very rarely written in the same language as the
> app.  Part of the idea is that you don't want people to have to know the
> language to configure your application.  I'm sure there are other
> reasons, that's just the first one that comes to mind.

Actually, I really like Ruby for configuration. It's actually just a
legacy decision that database.yml is in YAML. We've been discussing
various ways to refactor that into a nice Ruby configuration that
would probably be part of environment.rb and friends. But it just
hasn't been high priority enough to work on yet.
--
David Heinemeier Hansson
http://www.loudthinking.com -- Broadcasting Brain
http://www.basecamphq.com   -- Online project management
http://www.backpackit.com   -- Personal information manager
http://www.rubyonrails.com  -- Web-application framework
This topic is locked and can not be replied to.