Skip to content

Commit

Permalink
Documentation, railway tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
1602 committed Mar 27, 2012
1 parent 6ee7de0 commit 426efea
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
doc
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
doc:
makedoc lib/abstract-class.js lib/schema.js lib/validatable.js -t "JugglingDB API docs"

test:
@ONLY=memory ./support/nodeunit/bin/nodeunit test/*_test.*

.PHONY: test
.PHONY: doc
28 changes: 20 additions & 8 deletions lib/railway.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ var Schema = railway.orm.Schema;

railway.orm._schemas = [];

try {
var config = JSON.parse(fs.readFileSync(app.root + '/config/database.json', 'utf-8'))[app.set('env')];
} catch (e) {
console.log('Could not parse config/database.json');
throw e;
var confFile = app.root + '/config/database.json';
var config;

if (path.existsSync(confFile)) {
try {
config = JSON.parse(fs.readFileSync(confFile, 'utf-8'))[app.set('env')];
} catch (e) {
console.log('Could not parse config/database.json');
throw e;
}
} else {
config = {};
}

var schema = new Schema(config && config.driver || 'memory', config);
Expand All @@ -21,10 +28,15 @@ context = prepareContext(schema);
var schemaFile = app.root + '/db/schema.';
if (path.existsSync(schemaFile + 'js')) {
schemaFile += 'js';
} else {
} else if (path.existsSync(schemaFile + 'coffee')) {
schemaFile += 'coffee';
} else {
schemaFile = false;
}

if (schemaFile) {
runCode(schemaFile, context);
}
runCode(schemaFile, context);

// and freeze schemas
railway.orm._schemas.forEach(function (schema) {
Expand Down Expand Up @@ -67,7 +79,7 @@ function runCode(filename, context) {
context.t = context.t || t;
context.Buffer = Buffer;

var code = path.existsSync(filename) && require('fs').readFileSync(filename);
var code = path.existsSync(filename) && require('fs').readFileSync(filename).toString();
if (!code) return;
if (isCoffee) {
try {
Expand Down
46 changes: 35 additions & 11 deletions lib/validatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ function Validatable() {
*
* Default error message "can't be blank"
*
* @example `Post.validatesPresenceOf('title')`
* @example `Post.validatesPresenceOf('title', {message: 'Can not be blank'})`
* @example presence of title
* ```
* Post.validatesPresenceOf('title');
* ```
* @example with custom message
* ```
* Post.validatesPresenceOf('title', {message: 'Can not be blank'});
* ```
*
* @sync
*
* @nocode
Expand All @@ -42,12 +49,20 @@ Validatable.validatesPresenceOf = getConfigurator('presence');
* - max: too long
* - is: length is wrong
*
* @example `User.validatesLengthOf('password', {min: 7});`
* @example `User.validatesLengthOf('email', {max: 100});`
* @example `User.validatesLengthOf('state', {is: 2});`
* @example `User.validatesLengthOf('nick', {min: 3, max: 15});
* @sync
* @example length validations
* ```
* User.validatesLengthOf('password', {min: 7});
* User.validatesLengthOf('email', {max: 100});
* User.validatesLengthOf('state', {is: 2});
* User.validatesLengthOf('nick', {min: 3, max: 15});
* ```
* @example length validations with custom error messages
* ```
* User.validatesLengthOf('password', {min: 7, message: {min: 'too weak'}});
* User.validatesLengthOf('state', {is: 2, message: {is: 'is not valid state name'}});
* ```
*
* @sync
* @nocode
* @see helper/validateLength
*/
Expand All @@ -56,16 +71,18 @@ Validatable.validatesLengthOf = getConfigurator('length');
/**
* Validate numericality.
*
* @example `User.validatesNumericalityOf('age', { message: { number: '...' }});`
* @example `User.validatesNumericalityOf('age', {int: true, message: { int: '...' }});`
* @example
* ```
* User.validatesNumericalityOf('age', { message: { number: '...' }});
* User.validatesNumericalityOf('age', {int: true, message: { int: '...' }});
* ```
*
* Default error messages:
*
* - number: is not a number
* - int: is not an integer
*
* @sync
*
* @nocode
* @see helper/validateNumericality
*/
Expand All @@ -74,10 +91,17 @@ Validatable.validatesNumericalityOf = getConfigurator('numericality');
/**
* Validate inclusion in set
*
* @example `User.validatesInclusionOf('gender', {in: ['male', 'female']});`
* @example
* ```
* User.validatesInclusionOf('gender', {in: ['male', 'female']});
* User.validatesInclusionOf('role', {
* in: ['admin', 'moderator', 'user'], message: 'is not allowed'
* });
* ```
*
* Default error message: is not included in the list
*
* @sync
* @nocode
* @see helper/validateInclusion
*/
Expand Down

0 comments on commit 426efea

Please sign in to comment.