Documentation, railway tweaks

This commit is contained in:
Anatoliy Chakkaev 2012-03-27 23:48:23 +04:00
parent 6ee7de0716
commit 426efeabcf
4 changed files with 59 additions and 19 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
node_modules
doc

View File

@ -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

View File

@ -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) {
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);
@ -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) {
@ -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 {

View File

@ -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
@ -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
*/
@ -56,8 +71,11 @@ 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:
*
@ -65,7 +83,6 @@ Validatable.validatesLengthOf = getConfigurator('length');
* - int: is not an integer
*
* @sync
*
* @nocode
* @see helper/validateNumericality
*/
@ -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
*/