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 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: test:
@ONLY=memory ./support/nodeunit/bin/nodeunit test/*_test.* @ONLY=memory ./support/nodeunit/bin/nodeunit test/*_test.*
.PHONY: test .PHONY: test
.PHONY: doc

View File

@ -4,12 +4,19 @@ var Schema = railway.orm.Schema;
railway.orm._schemas = []; railway.orm._schemas = [];
var confFile = app.root + '/config/database.json';
var config;
if (path.existsSync(confFile)) {
try { try {
var config = JSON.parse(fs.readFileSync(app.root + '/config/database.json', 'utf-8'))[app.set('env')]; config = JSON.parse(fs.readFileSync(confFile, 'utf-8'))[app.set('env')];
} catch (e) { } catch (e) {
console.log('Could not parse config/database.json'); console.log('Could not parse config/database.json');
throw e; throw e;
} }
} else {
config = {};
}
var schema = new Schema(config && config.driver || 'memory', config); var schema = new Schema(config && config.driver || 'memory', config);
schema.log = log; schema.log = log;
@ -21,10 +28,15 @@ context = prepareContext(schema);
var schemaFile = app.root + '/db/schema.'; var schemaFile = app.root + '/db/schema.';
if (path.existsSync(schemaFile + 'js')) { if (path.existsSync(schemaFile + 'js')) {
schemaFile += 'js'; schemaFile += 'js';
} else { } else if (path.existsSync(schemaFile + 'coffee')) {
schemaFile += 'coffee'; schemaFile += 'coffee';
} else {
schemaFile = false;
} }
if (schemaFile) {
runCode(schemaFile, context); runCode(schemaFile, context);
}
// and freeze schemas // and freeze schemas
railway.orm._schemas.forEach(function (schema) { railway.orm._schemas.forEach(function (schema) {
@ -67,7 +79,7 @@ function runCode(filename, context) {
context.t = context.t || t; context.t = context.t || t;
context.Buffer = Buffer; 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 (!code) return;
if (isCoffee) { if (isCoffee) {
try { try {

View File

@ -24,8 +24,15 @@ function Validatable() {
* *
* Default error message "can't be blank" * Default error message "can't be blank"
* *
* @example `Post.validatesPresenceOf('title')` * @example presence of title
* @example `Post.validatesPresenceOf('title', {message: 'Can not be blank'})` * ```
* Post.validatesPresenceOf('title');
* ```
* @example with custom message
* ```
* Post.validatesPresenceOf('title', {message: 'Can not be blank'});
* ```
*
* @sync * @sync
* *
* @nocode * @nocode
@ -42,12 +49,20 @@ Validatable.validatesPresenceOf = getConfigurator('presence');
* - max: too long * - max: too long
* - is: length is wrong * - is: length is wrong
* *
* @example `User.validatesLengthOf('password', {min: 7});` * @example length validations
* @example `User.validatesLengthOf('email', {max: 100});` * ```
* @example `User.validatesLengthOf('state', {is: 2});` * User.validatesLengthOf('password', {min: 7});
* @example `User.validatesLengthOf('nick', {min: 3, max: 15}); * User.validatesLengthOf('email', {max: 100});
* @sync * 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 * @nocode
* @see helper/validateLength * @see helper/validateLength
*/ */
@ -56,8 +71,11 @@ Validatable.validatesLengthOf = getConfigurator('length');
/** /**
* Validate numericality. * Validate numericality.
* *
* @example `User.validatesNumericalityOf('age', { message: { number: '...' }});` * @example
* @example `User.validatesNumericalityOf('age', {int: true, message: { int: '...' }});` * ```
* User.validatesNumericalityOf('age', { message: { number: '...' }});
* User.validatesNumericalityOf('age', {int: true, message: { int: '...' }});
* ```
* *
* Default error messages: * Default error messages:
* *
@ -65,7 +83,6 @@ Validatable.validatesLengthOf = getConfigurator('length');
* - int: is not an integer * - int: is not an integer
* *
* @sync * @sync
*
* @nocode * @nocode
* @see helper/validateNumericality * @see helper/validateNumericality
*/ */
@ -74,10 +91,17 @@ Validatable.validatesNumericalityOf = getConfigurator('numericality');
/** /**
* Validate inclusion in set * 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 * Default error message: is not included in the list
* *
* @sync
* @nocode * @nocode
* @see helper/validateInclusion * @see helper/validateInclusion
*/ */