Skip to content

Commit

Permalink
Add fn to get conf and delegate in one step
Browse files Browse the repository at this point in the history
  • Loading branch information
LFDM committed May 27, 2014
1 parent cd3e591 commit 5238a49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/js/arethusa.core/configurator.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions spec/arethusa.core/configurator.service_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5238a49

Please sign in to comment.