Override Environment Settings - When they don't exist

What would be the recommended way to configure environment settings variables when something exists in one environment but does not exist in another.
For instance, I have a mail server configuration for production, test, and development environments, however, for local I write to file instead of sending mail.

In my settings struct I have something like:

`
settings = {
MAILAPP_ID = 999,
MAIL_URL = “url/of/my/mailService”,
MAIL_PASSWORD = “myPassWord”
};

`

Then I override these as expected in my other environments.

Local doesn’t hit the mail service though so I don’t have any mail settings to provide that would override production.
It looks like:

function local() { mailSettings.protocol = { class = "path.to.class.WriteFile.cfc", properties = { path = "test/mail/path" }; }

Thoughts?

Thanks,
Doug

Doug everything in the configure method should be for production. All other environments override this.

Doug, it looks like you are on the right track. Like Luis said, put your settings the way you want them in production in the configure method, and then override them as you see fit for the lower environments. Remembers, all settings are just structs and arrays, so you can use any CFML you need to append, remove, add, delete, overwrite, etc

Can you help clarify what your question is. What isn’t working specifically?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Luis,
Is that saying that if it is not present in an override environment then it does not exist in that environment?
Otherwise stated - If I configure my mail setting in production’s configure method but do not have mail settings in my local method, then when local the production settings will not exist?

And again, sorry for not formatting the subject line correctly - I blow that every time :slight_smile:

Hi Brad,
Ya, the whole config is working correctly - I just have this one use-case that I wasn’t sure about.
I’m wanting to understand what happens in this case:

`
settings ={
MAILAPP_ID =999,
MAIL_URL =“url/of/my/mailService”,
MAIL_PASSWORD =“myPassWord”
};

`
and then lower in the config I have:

function local(){ // no mail settings here - do they exist when i'm local? // I don't want them to exists here. }

Doug

If you don’t want them to exist in local, you will have to remove them as they exist in the core.

So things like this will work

structDelete( settings, “mailapp_id” );

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

There we go, thanks - I’m not sure why that didn’t come to me but that is exactly what needs to happen.

Thanks Luis, Brad!

Glad that makes sense. One quick bit of advice: make sure your environment overrides only affect the keys you want. For instance, this example would be bad because the local function completely replaces the settings struct instead of overriding a single key.

function configure(){
settings = {
foo = ‘prod’,
bar = ‘prod’
};
}

function local(){
settings = {
foo = ‘local’
};
}

Instead, you would want to do the following:

function configure(){
settings = {
foo = ‘prod’,
bar = ‘prod’
};
}

function local(){
// Target the specific key to override
settings.foo = ‘local’;
}

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Yes, that is exactly how I have my configuration setup. I am overriding settings.key in specific environments.

Thanks!
Doug