Skip to content

Commit

Permalink
[Store][Helper] Added support for wildcard loading of helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack12816 committed Feb 14, 2014
1 parent b38cf2e commit 3c3990c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var Store = function(namespaces)
*/
Store.prototype.get = function()
{
var self = this;
var namespace = null;
var key = null;

Expand All @@ -55,6 +56,29 @@ Store.prototype.get = function()
throw new Error('Arguments are not correctly set');
}

var lastCharPos = key.length -1;

// Check for an wildcard get request
if ('*' === key[lastCharPos]) {

var searchKey = key.substr(0, lastCharPos);
var map = {};

var found = this.list(namespace).filter(function(name) {
return ~name.indexOf(searchKey);
});

if (0 === found.length) {
return null;
}

found.forEach(function(name) {
map[name.substr(lastCharPos, name.length - 1)] = self.get(name);
});

return map;
}

return (this.namespaces[namespace] && this.namespaces[namespace][key]) || null;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"node-fs": "~0.1.7",
"async": "~0.2.9",
"winston": "~0.7.2",
"express-winston": "~0.2.1",
"express-winston": "~0.2.3",
"extend": "~1.2.1",
"moment": "~2.4.0",
"memory-cache": "~0.0.5",
Expand Down

0 comments on commit 3c3990c

Please sign in to comment.