Permalink
Browse files

Documentation, railway tweaks

  • Loading branch information...
1 parent 6ee7de0 commit 426efeabcf5b0382523703ef935376f4bb5a0f16 @1602 committed Mar 27, 2012
Showing with 59 additions and 19 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 Makefile
  3. +20 −8 lib/railway.js
  4. +35 −11 lib/validatable.js
View
@@ -1 +1,2 @@
node_modules
+doc
View
@@ -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
@@ -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);
@@ -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
@@ -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,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
*/
@@ -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
*/

0 comments on commit 426efea

Please sign in to comment.