Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
cades committed Jul 13, 2016
1 parent 1e071e8 commit 63f68b6
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
// blockManager._blockStack = stack
//

function concat(a, b) {
return a.concat(b)
}

var BlockManager = {
current: function() { return this._blockStack.top() },
currentSuite: function() { return this.current().suite },
Expand All @@ -32,20 +28,27 @@ var BlockManager = {
addAndToCurrent: function(fn) { this.current().ands.push(fn) },

allGivens: function() {
return this._blockStack.toArray().map(function(block){ return block.givens }).reduceRight(concat)
return this._collectAllClausesBy(function(blk){ return blk.givens })
},
allWhens: function() {
return this._blockStack.toArray().map(function(block){ return block.whens }).reduceRight(concat)
return this._collectAllClausesBy(function(blk){ return blk.whens })
},
allInvariants: function() {
return this._blockStack.toArray().map(function(block){ return block.invariants }).reduceRight(concat)
return this._collectAllClausesBy(function(blk){ return blk.invariants })
},
hasAnyThen: function() {
return this.current().thens.length > 0
},
currentAnds: function() {
return this.current().ands
},
_collectAllClausesBy: function(fn) {
return this._blockStack.toArray().map(fn).reduceRight(concat)
}
}

function concat(a, b) {
return a.concat(b)
}

module.exports = BlockManager

0 comments on commit 63f68b6

Please sign in to comment.