Skip to content

Commit

Permalink
fixes #6, only RBDefault into addDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
dbashford committed Jul 8, 2015
1 parent fd9cdda commit 93899fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ new RouteBuilder()
```

#### `RouteBuilder.addDefault`
This static function adds defaults to all RouteBuilder instances. This function takes a `RBDefault` object as input.
This static function adds defaults to all RouteBuilder instances. This function takes a `RBDefault` object as input. If something other than an RBDefault is passed in, an Error will be thrown.

```javascript
RouteBuilder.addDefault(new RBDefault(function(rb){
Expand Down
14 changes: 10 additions & 4 deletions src/route_builder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var utils = require("./utils")
, traverse = require('traverse')
var traverse = require("traverse")
, utils = require("./utils")
, RBDefault = require("./rb_defaults")
, replaceCheck = /^%.*%$/
;

Expand All @@ -18,6 +19,11 @@ RouteBuilder.defaultsArray = [];
* @param {Defaults} defaults object
*/
RouteBuilder.addDefault = function(configDefault) {

if(!(configDefault instanceof RBDefault)) {
throw Error("Must pass instance of RBDefault into addDefault");
}

RouteBuilder.defaultsArray.push(configDefault);
};

Expand Down Expand Up @@ -46,10 +52,10 @@ RouteBuilder.prototype._applyDefaults = function(atBuild) {
// if includes exist, only using it
if (_default.includes && _default.includes.length) {
if (utils.isIncluded(path, _default.includes || [])) {
(_default.func || _default)(that);
_default.func(that);
}
} else if (!utils.isExcluded(path, _default.excludes || [])) {
(_default.func || _default)(that);
_default.func(that);
}
});
}
Expand Down
11 changes: 6 additions & 5 deletions test/default_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ describe("defaults", function() {
expect(config.path).to.eql("barrr");
});


it("can be added directly", function() {
RouteBuilder.addDefault(function(rb) {});
expect(RouteBuilder.defaultsArray.length).to.eql(1);
it("cannot be added directly", function() {
var funct = function() {
RouteBuilder.addDefault(function(rb) {});
};
expect(funct).to.throw(Error);
});

it("can be added as RBDefault", function() {
Expand All @@ -87,7 +88,7 @@ describe("defaults", function() {
});

it("can be cleared", function() {
RouteBuilder.addDefault(function(rb) {});
RouteBuilder.addDefault(new RBDefault(function(rb) {}));
expect(RouteBuilder.defaultsArray.length).to.eql(1);
RouteBuilder.clearDefaults();
expect(RouteBuilder.defaultsArray.length).to.eql(0);
Expand Down

0 comments on commit 93899fc

Please sign in to comment.