Permalink
Browse files

More modelizer. got rid of idify and attributify

  • Loading branch information...
1 parent 908a2b7 commit 31cb4a069385fb654bef02e78634a6829195d1a8 @toots committed Jul 19, 2012
View
@@ -50,6 +50,7 @@ Get the facts!
* All asana items are [backbone](http://documentcloud.github.com/backbone/) models.
You can fetch and save them as is usually done with backbone models. However, asana
API does not allow to create or save some items.
+* Backbone models support ID map and modelize as provided by [backbone.modelizer](https://github.com/audiosocket/backbone.modelizer)
* All asana attributes are stored as model attributes. Creation arguments are those
documented in the Asana API.
* It is possible to pass models or IDs as attributes values.
@@ -61,12 +62,15 @@ Get the facts!
* `asna.Workspace` : Basic model for asana workspaces
* `asana.Workspaces` : Collection of all asana workspaces
* `asana.Project` : Basic model for asana projects
+ * `project.workspace` : Workpace for `project`
* `asana.Projects` : Collection of all asana projects
* `asana.Task` : Base task model
* `asana.Tasks` : Collection of available tasks.
* `task = new asana.Task params`:
* `task.Story` : Basic model to create a new story attached to
`task`
+ * `task.assignee` : User assigned to `task`
+ * `task.followers` : Collection of users following `task`
* `task.stories` : Collection of all stories attached to `task`
* `task.projects` : Collection of all projects to which `task` belongs
View
@@ -346,9 +346,9 @@ exports.extname = function(path) {
require.define("/asana.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var Asana, Backbone, addObjects, b64, clone, defaults, idify, isEmpty, querystringify, _ref;
+ var Asana, Backbone, addObjects, b64, clone, defaults, isEmpty, querystringify, _ref;
- _ref = require("./utils"), b64 = _ref.b64, defaults = _ref.defaults, clone = _ref.clone, idify = _ref.idify, querystringify = _ref.querystringify, isEmpty = _ref.isEmpty;
+ _ref = require("./utils"), b64 = _ref.b64, defaults = _ref.defaults, clone = _ref.clone, querystringify = _ref.querystringify, isEmpty = _ref.isEmpty;
Backbone = require("backbone");
@@ -382,14 +382,14 @@ require.define("/asana.coffee", function (require, module, exports, __dirname, _
return {
method: "PUT",
expects: 200,
- query: idify(model.asana.savedAttributes("PUT", model))
+ query: model.asana.savedAttributes("PUT", model)
};
},
create: function(model) {
return {
method: "POST",
expects: 201,
- query: idify(model.asana.savedAttributes("POST", model))
+ query: model.asana.savedAttributes("POST", model)
};
}
};
@@ -486,7 +486,7 @@ require.define("/asana.coffee", function (require, module, exports, __dirname, _
require.define("/utils.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var attributify, clone, fold, fromByteArray, idify, ioOptions, optName, utf8ToBytes, _;
+ var clone, fold, fromByteArray, ioOptions, optName, utf8ToBytes, _;
_ = require("underscore");
@@ -529,48 +529,6 @@ require.define("/utils.coffee", function (require, module, exports, __dirname, _
return res;
};
- module.exports.idify = idify = function(src) {
- var element;
- if (!((src != null) && typeof src === "object")) return src;
- if (src.id != null) return src.id;
- if (src instanceof Array) {
- return (function() {
- var _i, _len, _results;
- _results = [];
- for (_i = 0, _len = src.length; _i < _len; _i++) {
- element = src[_i];
- _results.push(idify(element));
- }
- return _results;
- })();
- }
- return fold(src, {}, function(cur, value, key) {
- cur[key] = idify(value);
- return cur;
- });
- };
-
- module.exports.attributify = attributify = function(src) {
- var element;
- if (!((src != null) && typeof src === "object")) return src;
- if (src.attributes != null) return src.attributes;
- if (src instanceof Array) {
- return (function() {
- var _i, _len, _results;
- _results = [];
- for (_i = 0, _len = src.length; _i < _len; _i++) {
- element = src[_i];
- _results.push(attributify(element));
- }
- return _results;
- })();
- }
- return fold(src, {}, function(cur, value, key) {
- cur[key] = attributify(value);
- return cur;
- });
- };
-
module.exports.isEmpty = _.isEmpty;
ioOptions = ["pretty", "fields", "expand"];
@@ -3202,12 +3160,12 @@ require.define("/node_modules/backbone/backbone.js", function (require, module,
require.define("/objects.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var attributify, clone, _ref;
+ var clone;
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
require("backbone.modelizer");
- _ref = require("./utils"), attributify = _ref.attributify, clone = _ref.clone;
+ clone = require("./utils").clone;
module.exports = function(src) {
var Collection, Model;
@@ -3223,10 +3181,6 @@ require.define("/objects.coffee", function (require, module, exports, __dirname,
Model.prototype.sync = src.sync;
- Model.prototype.set = function(attr, val, options) {
- return Model.__super__.set.call(this, attributify(attr), attributify(val), options);
- };
-
return Model;
})();
@@ -3376,6 +3330,20 @@ require.define("/objects.coffee", function (require, module, exports, __dirname,
Task.prototype.associations = function() {
return {
+ assignee: {
+ model: src.User
+ },
+ followers: {
+ collection: src.Users,
+ scope: "followers"
+ },
+ workspace: {
+ model: src.Workspace
+ },
+ workspaces: {
+ collection: src.Workspaces,
+ scope: "task"
+ },
stories: {
collection: src.Stories,
scope: "task"
@@ -3439,6 +3407,9 @@ require.define("/objects.coffee", function (require, module, exports, __dirname,
Project.prototype.associations = function() {
return {
+ workspace: {
+ model: src.Workspace
+ },
tasks: {
collection: src.Tasks,
scope: "project"
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,5 +1,5 @@
{b64,defaults,clone,
- idify,querystringify,
+ querystringify,
isEmpty} = require "./utils"
Backbone = require "backbone"
addObjects = require "./objects"
@@ -33,13 +33,13 @@ class Asana
method : "PUT"
expects : 200
query :
- idify model.asana.savedAttributes("PUT", model)
+ model.asana.savedAttributes("PUT", model)
create: (model) ->
method : "POST"
expects : 201
query :
- idify model.asana.savedAttributes("POST", model)
+ model.asana.savedAttributes("POST", model)
# For browserify..
if @asana.params.scheme == "https"
View
@@ -1,14 +1,11 @@
require "backbone.modelizer"
-{attributify, clone} = require "./utils"
+{clone} = require "./utils"
module.exports = (src) ->
class Model extends src.asana.Backbone.Model
asana : src.asana
sync : src.sync
- set: (attr, val, options) ->
- super attributify(attr), attributify(val), options
-
class Collection extends src.asana.Backbone.Collection
asana : src.asana
sync : src.sync
@@ -73,6 +70,13 @@ module.exports = (src) ->
url: => "/tasks/#{self.id}/stories"
associations: ->
+ assignee:
+ model: src.User
+ followers:
+ collection: src.Users
+ scope: "followers"
+ workspace:
+ model: src.Workspace
stories:
collection: src.Stories
scope: "task"
@@ -106,6 +110,8 @@ module.exports = (src) ->
res
associations: ->
+ workspace:
+ model: src.Workspace
tasks:
collection: src.Tasks
scope: "project"
Oops, something went wrong.

0 comments on commit 31cb4a0

Please sign in to comment.