Skip to content

Commit

Permalink
group#makeResource
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaa123 committed Jun 12, 2014
1 parent 3b98ee8 commit 317511d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/group.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
// A repository for resources.
// # Group
//
// Group related resources together; and lets you retrieve them.
//
// ## Create a group
//
// * makeGroup - Constructs a new group.
//
// ## Group methods
//
// * add - Adds resources to the group
// * makeResource - Creates a new resource
//

var util = require('./utils'),
makeResource = require('./resource'),
variadic = util.variadic,
fluent = util.fluent,
maybe = util.maybe,
extend = util.extend,
compose = util.compose;
maybe = util.maybe;

var makeGroup = module.exports = function () {
var _resources = {};
Expand All @@ -28,5 +39,9 @@ var makeGroup = module.exports = function () {
});
})));

_group.makeResource = function (name, path) {
return (_resources[name] = makeResource(name, path));
};

return _group;
};
12 changes: 12 additions & 0 deletions test/group_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,17 @@ describe('Group', function () {
});
});
});

it('Should allow to conveniently create a resource', function () {
var newResource = group.makeResource('test', '/test');

// Makes sure the created Resource is a resource
newResource.should.be.a.Function;
['attachTo', 'representation'].forEach(function(m) {
newResource[m].should.be.ok;
});

group('test').should.eql(newResource);
});
});
});

0 comments on commit 317511d

Please sign in to comment.