From c1406d259b99b564f20df2658a4d52d8d95a0d7f Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 2 Oct 2015 09:10:45 -0500 Subject: [PATCH] test(config): get method --- ionic/config/config.ts | 53 ++++++++++++++++++++++++++++++++ ionic/config/test/config.spec.ts | 28 ++++++++--------- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/ionic/config/config.ts b/ionic/config/config.ts index e7ecfdd42e..7be575d64b 100644 --- a/ionic/config/config.ts +++ b/ionic/config/config.ts @@ -20,6 +20,59 @@ export class IonicConfig { extend(this._settings, settings); } } + + get(key) { + let settings = this._settings; + + if (!isDefined(this._settings[key])) { + // if the value was already set this will all be skipped + // if there was no user config then it'll check each of + // the user config's platforms, which already contains + // settings from default platform configs + this._settings[key] = null; + + // check the platform settings object for this value + // loop though each of the active platforms + let activePlatformKeys = this._platforms; + let platformSettings = this._settings.platforms; + let platformObj = null; + if (platformSettings) { + let platformValue = undefined; + for (let i = 0; i < activePlatformKeys.length; i++) { + platformObj = platformSettings[ activePlatformKeys[i] ]; + + if (platformObj) { + if (isDefined(platformObj[key])) { + // check assigned platform settings + platformValue = platformObj[key]; + + } else if (platformObj.mode) { + // check the platform default mode settings + platformObj = IonicConfig.modeConfig(platformObj.mode); + if (platformObj) { + platformValue = platformObj[key]; + } + } + } + + } + if (isDefined(platformValue)) { + this._settings[key] = platformValue; + } + } + } + + // return key's value + // either it came directly from the user config + // or it was from the users platform configs + // or it was from the default platform configs + // in that order + if (isFunction(this._settings[key])) { + this._settings[key] = settings[key](this._platform); + } + return this._settings[key]; + } + /** * TODO */ diff --git a/ionic/config/test/config.spec.ts b/ionic/config/test/config.spec.ts index d02484e18e..1d14153559 100644 --- a/ionic/config/test/config.spec.ts +++ b/ionic/config/test/config.spec.ts @@ -9,19 +9,19 @@ export function run() { occupation: 'Weather Man' }); - expect(config.setting('name')).toEqual('Doc Brown'); - expect(config.setting('name')).toEqual('Doc Brown'); - expect(config.setting('occupation')).toEqual('Weather Man'); - expect(config.setting('occupation')).toEqual('Weather Man'); + expect(config.get('name')).toEqual('Doc Brown'); + expect(config.get('name')).toEqual('Doc Brown'); + expect(config.get('occupation')).toEqual('Weather Man'); + expect(config.get('occupation')).toEqual('Weather Man'); }); it('should get null setting', () => { let config = new IonicConfig(); - expect(config.setting('name')).toEqual(null); - expect(config.setting('name')).toEqual(null); - expect(config.setting('occupation')).toEqual(null); - expect(config.setting('occupation')).toEqual(null); + expect(config.get('name')).toEqual(null); + expect(config.get('name')).toEqual(null); + expect(config.get('occupation')).toEqual(null); + expect(config.get('occupation')).toEqual(null); }); it('should set/get single setting', () => { @@ -29,10 +29,10 @@ export function run() { config.setting('name', 'Doc Brown'); config.setting('occupation', 'Weather Man'); - expect(config.setting('name')).toEqual('Doc Brown'); - expect(config.setting('name')).toEqual('Doc Brown'); - expect(config.setting('occupation')).toEqual('Weather Man'); - expect(config.setting('occupation')).toEqual('Weather Man'); + expect(config.get('name')).toEqual('Doc Brown'); + expect(config.get('name')).toEqual('Doc Brown'); + expect(config.get('occupation')).toEqual('Weather Man'); + expect(config.get('occupation')).toEqual('Weather Man'); }); it('should init w/ given config settings', () => { @@ -40,8 +40,8 @@ export function run() { name: 'Doc Brown', occupation: 'Weather Man' }); - expect(config.setting('name')).toEqual('Doc Brown'); - expect(config.setting('occupation')).toEqual('Weather Man'); + expect(config.get('name')).toEqual('Doc Brown'); + expect(config.get('occupation')).toEqual('Weather Man'); }); it('should get settings object', () => {