From 5238a4987c597fcb5bcfeec3146533adbc7815ff Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Tue, 27 May 2014 10:06:46 +0200 Subject: [PATCH] Add fn to get conf and delegate in one step --- app/js/arethusa.core/configurator.service.js | 6 ++++++ .../arethusa.core/configurator.service_spec.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/js/arethusa.core/configurator.service.js b/app/js/arethusa.core/configurator.service.js index c13b56f94..108e3577c 100644 --- a/app/js/arethusa.core/configurator.service.js +++ b/app/js/arethusa.core/configurator.service.js @@ -239,6 +239,12 @@ angular.module('arethusa.core').service('configurator', function($injector, $htt }); }; + this.getConfAndDelegate = function(name, obj, keys) { + obj.conf = self.configurationFor(name); + self.delegateConf(obj, keys); + return obj; + }; + this.getRetrievers = function(retrievers) { return arethusaUtil.inject({}, retrievers, function(memo, name, conf) { var Retriever = self.getService(name); diff --git a/spec/arethusa.core/configurator.service_spec.js b/spec/arethusa.core/configurator.service_spec.js index f3b9f8039..c954a1a24 100644 --- a/spec/arethusa.core/configurator.service_spec.js +++ b/spec/arethusa.core/configurator.service_spec.js @@ -256,6 +256,24 @@ describe('configurator', function() { })); }); + describe('this.getConfAndDelegate', function() { + it('convenience fn to get conf and delegate in one step', inject(function(configurator) { + configurator.configuration = conf1; + var obj = {}; + configurator.getConfAndDelegate('morph', obj, ['a']); + expect(obj.name).toEqual('morph'); + expect(obj.conf).toBeTruthy(); + expect(obj.hasOwnProperty('a')).toBeTruthy(); + })); + + it('returns the given object', inject(function(configurator) { + configurator.configuration = conf1; + var obj = {}; + var res = configurator.getConfAndDelegate('morph', obj); + expect(obj).toBe(res); + })); + }); + describe('this.getService', function() { it('retrieves an angular instance by name', inject(function(configurator) { expect(configurator.getService('x')).toEqual(mock1);