Skip to content

Instantly share code, notes, and snippets.

@heymichaelp
Last active August 29, 2015 14:03
Show Gist options
  • Save heymichaelp/b2fb4277a2200c7b6768 to your computer and use it in GitHub Desktop.
Save heymichaelp/b2fb4277a2200c7b6768 to your computer and use it in GitHub Desktop.
Policy Objects: Example
var _ = require('underscore');
var PassingStudentPolicy = require('./passingStudentPolicy');
var SportsEligibilityPolicy = function(student) {
this.student = student;
};
SportsEligibilityPolicy.prototype = _.extend(SportsEligibilityPolicy.prototype, {
run: function() {
return this.isNotExpelled() && this.isNotSuspended() && this.isPassing();
},
isNotExpelled: function() {
return this.student.isExpelled !== true;
},
isNotSuspended: function() {
return this.student.isSuspended !== true;
},
isPassing: function() {
return new PassingStudentPolicy(this.student).run();
}
});
module.exports = SportsEligibilityPolicy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment