[Config-loader] [Config Loader] Translating dir/file names to keys was updated

Config Loader noreply at google.com
Sat Aug 30 17:47:11 BST 2008


Clinton Gormley updated the page Translating dir/file names to keys. View  =

the changes below.
Color key: Insertion | Deletion


Consider the following tree:

config/
db/
main/
creds_production.yml
creds_development.yml

When we are running in production, we want to load the creds_production  =

file. When on a development machine, we want to run load the  =

creds_development file.

Whichever file we load, we want it to be inserted into the config tree with=
  =

the key ' creds'. This assumes we're using

load_level =3D> 'path' .

So, we could say:

my $role =3D $ENV{ROLE} || 'development';

my $load_if =3D $role eq 'development'
? qr/_development$/
: qr/_production$/;

my $load_unless =3D $role eq 'development'
? qr/_production$/
: qr/_development$/;

my $c =3D Config::Loader->new({
path =3D> '/path/to/config',
load _if =3D> $load_if,
load_unless =3D> $load_unless
});

But that doesn't help us with the naming of the key - it would be loaded  =

as ' creds_production ' or ' creds_development '.

So we have two choices:


provide another parameter, eg. load_filename_as

use the return value of load_if* as the name to use
The first is more explicit, but requires regexes to be repeated. The second=
  =

is slightly less obvious, but more compact.

So we would rewrite the above as:


my $role =3D $ENV{ROLE} || 'development';

my $load_if =3D $role eq 'development'
? qr/(.+)_development$/
: qr/(.+)_production$/;

my $load_unless =3D $role eq 'development'
? qr/_production$/
: qr/_development$/;

my $c =3D Config::Loader->new({
path =3D> '/path/to/config',
load _if =3D> $load_if,
load_unless =3D> $load_unless
});

The same issue does not apply to load_unless as, obviously, we're not going=
  =

to load the file.

We could use the same mechanism for merge_if .


Checking for "false" / do_not_load

If we're not just expecting a boolean return value from load_if , then a  =

false value may be an allowable 'true' value. We could check for defined,  =

but probably a more 'friendly' solution would be just to check for a  =

positive length,




Go to page: Translating dir/file names to keys


-------------
You requested this notification from Google Sites. You can unsubscribe at  =

any time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/config-loader/attachments/20080830/=
d448bd65/attachment-0001.htm


More information about the Config-loader mailing list