1
0
Fork 0

Foxx: Add examples for each of the methods of Repository

This commit is contained in:
Lucas Dohmen 2014-06-13 16:24:58 +02:00
parent 509c2c9c9f
commit d57f88507b
1 changed files with 93 additions and 5 deletions

View File

@ -48,15 +48,14 @@ var Repository,
/// 1. Model: The prototype of a model. If you do not provide it, it will default /// 1. Model: The prototype of a model. If you do not provide it, it will default
/// to Foxx.Model /// to Foxx.Model
/// 2. Prefix: You can provide the prefix of the application if you need it in /// 2. Prefix: You can provide the prefix of the application if you need it in
/// your Repository (for some AQL queries probably). Get it from the Foxx.Controller /// your Repository (for some AQL queries probably).
/// via the `collectionPrefix` attribute.
/// ///
/// *Examples* /// *Examples*
/// ///
/// ```javascript /// ```javascript
/// instance = new Repository(app.collection("my_collection")); /// instance = new Repository(appContext.collection("my_collection"));
/// // or: /// // or:
/// instance = new Repository(app.collection("my_collection"), { /// instance = new Repository(appContext.collection("my_collection"), {
/// model: MyModelPrototype, /// model: MyModelPrototype,
/// prefix: app.collectionPrefix, /// prefix: app.collectionPrefix,
/// }); /// });
@ -115,6 +114,12 @@ _.extend(Repository.prototype, {
/// ///
/// Expects a model. Will set the ID and Rev on the model. /// Expects a model. Will set the ID and Rev on the model.
/// Returns the model. /// Returns the model.
///
/// *Examples*
///
/// ```javascript
/// repository.save(my_model);
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
save: function (model) { save: function (model) {
@ -135,6 +140,13 @@ _.extend(Repository.prototype, {
/// Find a model by its ID /// Find a model by its ID
/// ///
/// Returns the model for the given ID. /// Returns the model for the given ID.
///
/// *Examples*
///
/// ```javascript
/// var myModel = repository.byId('test/12411');
/// myModel.get('name');
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
byId: function (id) { byId: function (id) {
@ -150,6 +162,13 @@ _.extend(Repository.prototype, {
/// Find all models by an example /// Find all models by an example
/// ///
/// Returns an array of models for the given ID. /// Returns an array of models for the given ID.
///
/// *Examples*
///
/// ```javascript
/// var myModel = repository.byExample({ amazing: true });
/// myModel[0].get('name');
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
byExample: function (example) { byExample: function (example) {
@ -167,6 +186,13 @@ _.extend(Repository.prototype, {
/// Find the first model that matches the example. /// Find the first model that matches the example.
/// ///
/// Returns a model that matches the given example. /// Returns a model that matches the given example.
///
/// *Examples*
///
/// ```javascript
/// var myModel = repository.firstExample({ amazing: true });
/// myModel.get('name');
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
firstExample: function (example) { firstExample: function (example) {
@ -180,6 +206,13 @@ _.extend(Repository.prototype, {
/// `all()` /// `all()`
/// ///
/// Returns an array of models that matches the given example. /// Returns an array of models that matches the given example.
///
/// *Examples*
///
/// ```javascript
/// var myModel = repository.all();
/// myModel[0].get('name');
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -194,6 +227,12 @@ _.extend(Repository.prototype, {
/// Remove the model from the repository /// Remove the model from the repository
/// ///
/// Expects a model /// Expects a model
///
/// *Examples*
///
/// ```javascript
/// repository.remove(myModel);
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -204,6 +243,12 @@ _.extend(Repository.prototype, {
/// Remove the document with the given ID /// Remove the document with the given ID
/// ///
/// Expects an ID of an existing document. /// Expects an ID of an existing document.
///
/// *Examples*
///
/// ```javascript
/// repository.removeById('test/12121');
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
removeById: function (id) { removeById: function (id) {
@ -218,6 +263,12 @@ _.extend(Repository.prototype, {
/// Remove all documents that match the example /// Remove all documents that match the example
/// ///
/// Find all documents that fit this example and remove them. /// Find all documents that fit this example and remove them.
///
/// *Examples*
///
/// ```javascript
/// repository.removeByExample({ toBeDeleted: true });
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
removeByExample: function (example) { removeByExample: function (example) {
@ -236,6 +287,13 @@ _.extend(Repository.prototype, {
/// Find the model in the database by its `_id` and replace it with this version. /// Find the model in the database by its `_id` and replace it with this version.
/// Expects a model. Sets the Revision of the model. /// Expects a model. Sets the Revision of the model.
/// Returns the model. /// Returns the model.
///
/// *Examples*
///
/// ```javascript
/// myModel.set('name', 'Jan Steemann');
/// repository.replace(myModel);
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
replace: function (model) { replace: function (model) {
@ -256,6 +314,12 @@ _.extend(Repository.prototype, {
/// Find the model in the database by the given ID and replace it with the given. /// Find the model in the database by the given ID and replace it with the given.
/// model. /// model.
/// Sets the ID and Revision of the model and also returns it. /// Sets the ID and Revision of the model and also returns it.
///
/// *Examples*
///
/// ```javascript
/// repository.replaceById('test/123345', myNewModel);
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
replaceById: function (id, model) { replaceById: function (id, model) {
@ -265,7 +329,6 @@ _.extend(Repository.prototype, {
model.set(id_and_rev); model.set(id_and_rev);
return model; return model;
} }
});
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @startDocuBlock JSF_foxx_repository_replaceByExample /// @startDocuBlock JSF_foxx_repository_replaceByExample
@ -276,6 +339,12 @@ _.extend(Repository.prototype, {
/// Find the model in the database by the given example and replace it with the given. /// Find the model in the database by the given example and replace it with the given.
/// model. /// model.
/// Sets the ID and Revision of the model and also returns it. /// Sets the ID and Revision of the model and also returns it.
///
/// *Examples*
///
/// ```javascript
/// repository.replaceByExample({ replaceMe: true }, myNewModel);
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -289,6 +358,12 @@ _.extend(Repository.prototype, {
/// ///
/// Find an item by ID and update it with the attributes in the provided object. /// Find an item by ID and update it with the attributes in the provided object.
/// Returns the updated model. /// Returns the updated model.
///
/// *Examples*
///
/// ```javascript
/// repository.updateById('test/12131', { newAttribute: 'awesome' });
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -298,6 +373,12 @@ _.extend(Repository.prototype, {
/// ///
/// Find an item by example and update it with the attributes in the provided object. /// Find an item by example and update it with the attributes in the provided object.
/// Returns the updated model. /// Returns the updated model.
///
/// *Examples*
///
/// ```javascript
/// repository.updateByExample({ findMe: true }, { newAttribute: 'awesome' });
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -310,8 +391,15 @@ _.extend(Repository.prototype, {
/// `count()` /// `count()`
/// ///
/// Return the number of entries in this collection /// Return the number of entries in this collection
///
/// *Examples*
///
/// ```javascript
/// repository.count();
/// ```
/// @endDocuBlock /// @endDocuBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
});
Repository.extend = backbone_helpers.extend; Repository.extend = backbone_helpers.extend;