Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closes #216, Update example apps to use the updateAttributes method t…

…o update attributes, also update other code.

Also fixed a bug where file.requireLocal was being called but it should've been utils.file.requireLocal.
  • Loading branch information...
commit a53673346be3ea0cd4b408db67e397a02e575dee 1 parent 3e45d54
@larzconwell larzconwell authored
View
6 examples/todo_app/app/controllers/todos.js
@@ -47,8 +47,8 @@ var Todos = function () {
this.update = function (req, resp, params) {
var self = this;
geddy.model.Todo.first(params.id, function (err, todo) {
- todo.status = params.status;
- todo.title = params.title;
+ todo.updateAttributes(params);
+
todo.save(function (err, data) {
if (err) {
params.errors = err;
@@ -63,7 +63,7 @@ var Todos = function () {
this.remove = function (req, resp, params) {
var self = this;
- geddy.model.adapter.Todo.remove(params.id, function(err){
+ geddy.model.Todo.remove(params.id, function(err){
if (err) {
params.errors = err;
self.transfer('edit');
View
6 examples/todo_app/config/init.js
@@ -4,8 +4,4 @@ if (geddy.config.environment != 'development') {
process.addListener('uncaughtException', function (err) {
geddy.log.error(JSON.stringify(err));
});
-}
-geddy.todos = [];
-geddy.model.adapter = {};
-geddy.model.adapter.Todo = require(process.cwd() + '/lib/model_adapters/todo').Todo;
-
+}
View
60 examples/todo_app/lib/model_adapters/todo.js
@@ -1,60 +0,0 @@
-var Todo = new (function () {
-
- this.all = function (callback) {
- callback(null, geddy.todos);
- }
-
- this.load = function (id, callback) {
-
- for (var i in geddy.todos) {
- if (geddy.todos[i].id == id) {
- return callback(null, geddy.todos[i]);
- }
- }
- callback({message: "To Do not found"}, null);
-
- };
-
- this.save = function (todo, opts, callback) {
-
- if (typeof callback != 'function') {
- callback = function(){};
- }
-
- var todoErrors = null;
- for (var i in geddy.todos) {
-
- // if it's already there, save it
- if (geddy.todos[i].id == todo.id) {
- geddy.todos[i] = todo;
- todoErrors = geddy.model.Todo.create(todo).errors;
- return callback(todoErrors, todo);
- }
-
- }
- todo.saved = true;
- geddy.todos.push(todo);
- return callback(null, todo);
-
- }
-
- this.remove = function(id, callback) {
-
- if (typeof callback != 'function') {
- callback = function(){};
- }
-
- for (var i in geddy.todos) {
- if (geddy.todos[i].id == id) {
- geddy.todos.splice(i, 1);
- return callback(null);
- }
- }
-
- return callback({message: "To Do not found"});
-
- }
-
-})();
-
-exports.Todo = Todo;
View
20 examples/todo_app_coffee/app/controllers/todos.coffee
@@ -3,13 +3,7 @@ class Todos
index: (req, resp, params) ->
self = this
- geddy.model.adapter.Todo.all
- status:
- 'in': ['open', 'done']
- , sort:
- status: -1
- title: 1
- , (err, todos) ->
+ geddy.model.Todo.all (err, todos) ->
self.respond params: params, todos: todos
add: (req, resp, params) ->
@@ -19,7 +13,6 @@ class Todos
self = this
todo = geddy.model.Todo.create
title: params.title
- id: geddy.string.uuid(10)
status: 'open'
todo.save (err, data) ->
@@ -31,19 +24,18 @@ class Todos
show: (req, resp, params) ->
self = this
- geddy.model.adapter.Todo.load params.id, (err, todo) ->
+ geddy.model.Todo.load params.id, (err, todo) ->
self.respond params: params, todo: todo
edit: (req, resp, params) ->
self = this
- geddy.model.adapter.Todo.load params.id, (err, todo) ->
+ geddy.model.Todo.load params.id, (err, todo) ->
self.respond params: params, todo: todo
update: (req, resp, params) ->
self = this
- geddy.model.adapter.Todo.load params.id, (err, todo) ->
- todo.status = params.status
- todo.title = params.title
+ geddy.model.Todo.load params.id, (err, todo) ->
+ todo.updateAttributes params
todo.save (err, data) ->
if err
@@ -54,7 +46,7 @@ class Todos
remove: (req, resp, params) ->
self = this
- geddy.model.adapter.Todo.remove params.id, (err) ->
+ geddy.model.Todo.remove params.id, (err) ->
if err
params.errors = err
self.transfer 'edit'
View
5 examples/todo_app_coffee/app/models/todo.coffee
@@ -3,9 +3,6 @@ Todo = ->
title:
type: 'string'
required: true
- id:
- type: 'string'
- required: true
status:
type: 'string'
required: true
@@ -16,6 +13,4 @@ Todo = ->
@validatesWithFunction 'status', (status) ->
status == 'open' || status == 'done'
- @adapter = 'mongo'
-
Todo = geddy.model.register 'Todo', Todo
View
9 examples/todo_app_coffee/config/development.coffee
@@ -2,14 +2,11 @@ config =
detailedErrors: false
hostname: null
port: 4000
+ model:
+ defaultAdapter: 'memory'
sessions:
store: 'memory'
key: 'sid'
expiry: 14 * 24 * 60 * 60
- db:
- mongo:
- db: 'todo'
-
-module.exports = config
-
+module.exports = config
View
15 examples/todo_app_coffee/config/development.coffee.mongo
@@ -0,0 +1,15 @@
+config =
+ detailedErrors: false
+ hostname: null
+ port: 4000
+ model:
+ defaultAdapter: 'mongo'
+ db:
+ mongo:
+ dbname: 'model_test'
+ sessions:
+ store: 'memory'
+ key: 'sid'
+ expiry: 14 * 24 * 60 * 60
+
+module.exports = config
View
5 examples/todo_app_coffee/config/init.coffee
@@ -1,8 +1,3 @@
-mongo = require 'mongodb-wrapper'
-
-geddy.db = mongo.db 'localhost', 27017, 'todo'
-geddy.db.collection 'todos'
-
# Add uncaught-exception handler in prod-like environments
if geddy.config.environment != 'development'
process.addListener 'uncaughtException', (err) ->
View
2  lib/config.js
@@ -39,7 +39,7 @@ config = new (function () {
if (fileBaseName === env || fileBaseName === 'environment') {
if (fileExt === '.coffee') {
// fileName is a CoffeeScript file so try to require it
- useCoffee = useCoffee || file.requireLocal('coffee-script');
+ useCoffee = useCoffee || utils.file.requireLocal('coffee-script');
}
appBaseConfig = require(dir + '/config/environment');
appEnvConfig = require(dir + '/config/' + baseConfig.environment);
Please sign in to comment.
Something went wrong with that request. Please try again.