bookshelf-fields
Advanced tools
Comparing version 0.4.0 to 0.4.1
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
var CheckIt, deep_clone, enable_validation, exports, f, field, fields, k, plugin, ref, | ||
var CheckIt, deep_clone, enable_validation, f, field, fields, k, plugin, ref, | ||
slice = [].slice; | ||
@@ -30,18 +30,2 @@ | ||
var model, old_format, old_parse; | ||
if (instance.__helpers_fp == null) { | ||
instance.__helpers_fp = {}; | ||
} | ||
instance.__helpers_fp.enable_validation = function(options) { | ||
return enable_validation(this, options); | ||
}; | ||
instance.__helpers_fp.field = function() { | ||
var args; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
return field.apply(null, [this].concat(slice.call(args))); | ||
}; | ||
instance.__helpers_fp.fields = function() { | ||
var args; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
return fields.apply(null, [this].concat(slice.call(args))); | ||
}; | ||
if (options == null) { | ||
@@ -55,2 +39,17 @@ options = {}; | ||
instance.Checkit = CheckIt; | ||
if (options.augementModel || options.augement_model) { | ||
instance.Model.enableValidation = instance.Model.enable_validation = function(options) { | ||
return enable_validation(this, options); | ||
}; | ||
instance.Model.field = function() { | ||
var args; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
return field.apply(null, [this].concat(slice.call(args))); | ||
}; | ||
instance.Model.fields = function() { | ||
var args; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
return fields.apply(null, [this].concat(slice.call(args))); | ||
}; | ||
} | ||
model = instance.Model.prototype; | ||
@@ -148,17 +147,20 @@ model.validate = function(self, attrs, options) { | ||
exports = { | ||
plugin: plugin, | ||
field: field, | ||
fields: fields, | ||
enable_validation: enable_validation | ||
}; | ||
plugin.plugin = plugin; | ||
plugin.field = field; | ||
plugin.fields = fields; | ||
plugin.enable_validation = enable_validation; | ||
plugin.enableValidation = enable_validation; | ||
ref = require('./fields'); | ||
for (k in ref) { | ||
f = ref[k]; | ||
exports[k] = f; | ||
plugin[k] = f; | ||
} | ||
module.exports = exports; | ||
module.exports = plugin; | ||
}).call(this); |
{ | ||
"name": "bookshelf-fields", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Bookshelf fields", | ||
@@ -20,3 +20,2 @@ "main": "lib/bookshelf-fields.js", | ||
"devDependencies": { | ||
"bookshelf-coffee-helpers": "*", | ||
"chai": "*", | ||
@@ -23,0 +22,0 @@ "chai-as-promised": "~5.1.0", |
@@ -42,5 +42,4 @@ bookshelf-fields | ||
Now you are ready to add fields information to models. There are two equivalent ways to do it: with | ||
exported functions 'field', 'fields' and 'enable_validation' and with the same methods, mixed into a | ||
Function prototype. If you choose the second way you need to call | ||
`Fields.pollute_function_prototype()` before. | ||
exported functions 'field', 'fields' and 'enableValidation' and with the same methods, mixed into a | ||
Model prototype. If you choose the second way you need to pass option `augement_model: true` to plugin. | ||
@@ -67,10 +66,2 @@ ## Provided helpers | ||
## With [bookshelf-coffee-helpers](https://github.com/bogus34/bookshelf-coffee-helpers) | ||
* `db.pollute_function_prototype()` - add methods `enable_validation`, `field` and `fields` to a | ||
Function prototype. Those methods have the same signature as a same-named functions excluding | ||
first 'model' parameter. | ||
* `db.cleanup_function_prototype()` - remove methods added in `pollute_function_prototype` | ||
## <a id="fields"></a>Fields | ||
@@ -172,6 +163,4 @@ | ||
db.plugin Fields.plugin | ||
db.plugin Fields.plugin(augement_model: true) | ||
Fields.pollute_function_prototype() | ||
class User extends db.Model | ||
@@ -184,4 +173,2 @@ tableName: 'users' | ||
Fields.cleanup_function_prototype() | ||
new User(username: 'bogus', email: 'bogus@test.com').save() | ||
@@ -188,0 +175,0 @@ .otherwise (errors) -> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8
53118
486
223