Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit f33275345e10af7a43224c7c95f4adf960116071 @gushov committed May 27, 2012
Showing 1,186 changed files with 169,417 additions and 0 deletions.
@@ -0,0 +1 @@
+/node_modules/
@@ -0,0 +1,22 @@
+Copyright (c) 2012 August Hovland
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
+# model
+
+The best project ever.
+
+## Getting Started
+Install the module with: `npm install model`
+
+```javascript
+var model = require('model');
+model.awesome(); // "awesome"
+```
+
+## Documentation
+_(Coming soon)_
+
+## Examples
+_(Coming soon)_
+
+## Contributing
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt).
+
+## Release History
+_(Nothing yet)_
+
+## License
+Copyright (c) 2012 August Hovland
+Licensed under the MIT license.
@@ -0,0 +1,39 @@
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: '<json:package.json>',
+ test: {
+ files: ['test/**/*.js']
+ },
+ lint: {
+ files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js']
+ },
+ watch: {
+ files: '<config:lint.files>',
+ tasks: 'default'
+ },
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ node: true
+ },
+ globals: {
+ exports: true
+ }
+ }
+ });
+
+ // Default task.
+ grunt.registerTask('default', 'lint test');
+
+};
@@ -0,0 +1,172 @@
+/**
+ * lilmodel
+ * https://github.com/ahovland-nokia/model
+ *
+ * Copyright (c) 2012 August Hovland
+ * Licensed under the MIT license.
+ */
+
+(function (exports) {
+
+ "use strict";
+
+ var sync;
+ var model = {
+ /**
+ * Create instance of model
+ */
+ create: function (attrs) {
+
+ var instance = Object.create(this, {
+ attrs: {
+ value: {},
+ writable: true,
+ enumerable: false,
+ configurable : false
+ }
+ });
+
+ return instance.init(attrs);
+
+ },
+
+ /**
+ * Create a collection of models
+ */
+ collection: function (attrs) {
+
+ var models = [];
+
+ if (attrs && attrs.length) {
+
+ models = attrs.map(function (attr) {
+ return Object.getPrototypeOf(attr) === this ? attr : this.create(attr);
+ }.bind(this));
+
+ }
+
+ return models;
+
+ },
+
+ /**
+ * Model init function sets property values
+ */
+ init: function (attrs) {
+
+ var config = this.config;
+
+ Object.keys(config).forEach(function (prop) {
+
+ var dfault = config && typeof config[prop] !== 'function' ? config[prop] : undefined;
+ this[prop] = attrs && typeof attrs[prop] !== 'undefined' ? attrs[prop] : dfault;
+
+ }.bind(this));
+
+ return this;
+ },
+
+ /**
+ * Method should be overridden to validate this.attrs values
+ */
+ validate: function () {
+ return { isValid: true };
+ },
+
+ /**
+ * If model is valid call sync save
+ */
+ save: function (next) {
+
+ var validator = this.validate();
+ var method = this._id ? 'update' : 'create';
+
+ if (validator.isValid) {
+ sync(method, this, next);
+ } else {
+ next(validator.error);
+ }
+
+ },
+
+ /**
+ * Call sync fetch
+ */
+ fetch: function (next) {
+ sync('fetch', this, next);
+ },
+
+ /**
+ * Call sync find
+ */
+ find: function (next) {
+ sync('find', this, next);
+ },
+
+ /**
+ * Call sync destroy
+ */
+ destroy: function (next) {
+ sync('delete', this, next);
+ },
+
+ //******** DELETE TEMP FUNCTION*********//
+ serialize: function () {
+ return this;
+ }
+ };
+
+ exports.sync = function (handler) {
+
+ sync = function (method, model, next) {
+
+ handler(method, model, function (err, result) {
+
+ if (err) {
+ next(err);
+ } else if (result && typeof result.length === 'number') {
+ next(err, model.collection(result));
+ } else {
+ next(err, model.create(result));
+ }
+
+ });
+
+ };
+
+ };
+
+ exports.model = function (props) {
+
+ var instance = Object.create(model);
+
+ Object.keys(props).forEach(function (prop) {
+
+ var isModel = typeof props[prop] === 'function';
+
+ Object.defineProperty(instance, prop, {
+
+ get: function () {
+ return typeof this.attrs[prop] !== 'undefined' ? this.attrs[prop] : '';
+ },
+
+ set: function (value) {
+ this.attrs[prop] = isModel ? props[prop](value) : value;
+ }
+
+ });
+
+ });
+
+ Object.defineProperty(instance, 'config', {
+ value: props,
+ writable: true,
+ enumerable: false,
+ configurable: false
+ });
+
+ return instance;
+
+ };
+
+}(typeof exports === 'undefined' ? (this.lilmodel = {}) : exports));

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

Oops, something went wrong.

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

Oops, something went wrong.

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

Oops, something went wrong.

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

Oops, something went wrong.

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

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit f332753

Please sign in to comment.