<commit_before>KnockoutApp Documentation
=========================

## KnockoutApp.Model

A model is used to store data and has methods to connect it with the server.

	var Task = KnockoutApp.Model.extend({

		defaultAttributes: function(){
			return {
				title: ko.observable("A task to do"),
				done: ko.observable(false)
			};
		}

	});

	var task1 = new Task({
		title: "my first task"
	});

### extend
KnockoutApp.Model.extend( [ protoProps, staticProps ] )

Give a Model the possibility to be extended, accepts two objects: one to extend instance properties and the second one for static properties.

	var Task = KnockoutApp.Model.Extend({
		//instance properties and methods
	},
	{
		//static properties and methods
	});

Used to extend model prototype and static methods.

### constructor / initialize
new KnockoutApp.Model( [ attributes, collection ] )

Create a new model instance, accepts two parameters:

- an object of *attributes* to be set

- if the model is inside a collection you can pass as a second parameter a reference to the collection

Instead of overriding the constructor use the *initialize* method that will be called using *apply()* from the collection so *this* will be the model.

Remember that KnockoutJS observable properties can't be defined in the model's prototype so *initialize* is the perfect place.

	Task.prototype.initialize = function(){
		//code code code
	};

### id
model.id()

An observable property, used to communicate with the server.

If its value is set to *false* model.isNew() will return true.

### attributes
model.attributes

A simple object where all the model's attributes are stored.

### defaultAttributes
model.defaultAttributes()

A function that returns an object with the default attributes of the model.

You can also define KnockoutJS observable properties.

*Must be a function since I've not implemented any clone method.*

	Task.prototype.defaultAttributes = function(){
		return {
			title: ko.observable("default title"),
			done: ko.observable(false)
		}
	}

### collection
model.collection

If the model is stored in a Collection it stores a reference to the collection.

### sync
model.sync

If this property is set, it will be used instead of KnockoutApp.Sync.

### isNew
model.isNew()

Used to detect if the model has been saved to the server.

Return *false* if model.id() is not *false*.

### fetch
model.fetch( [ options ] )

Fetch a model from the server and overrides its attributes with the one fetched.

Accepts as a parameter an *options* object tha will be passed to Knockout.Sync.

### save
model.save( [ options ] )

If model.isNew() the model will be created on the server, otherwise it will be saved.

Accepts as a parameter an *options* object that will be passed to KnockoutApp.Sync.

### destroy
model.destroy( [ options ] )

If the model is inside a collection, remove it from the collection.

If the model has been saved to the server, delete it on the server.

Accepts as a parameter an *options* object tha will be passed to Knockout.Sync.

### url
model.url()

If the model is inside a collection return the collection url plus the id property if the item has been saved to the server.

### validate
model.validate()

Not implementd, returns true.
<commit_msg>documentation for modelName<commit_after>KnockoutApp Documentation
=========================

## KnockoutApp.Model

A model is used to store data and has methods to connect it with the server.

	var Task = KnockoutApp.Model.extend({

		defaultAttributes: function(){
			return {
				title: ko.observable("A task to do"),
				done: ko.observable(false)
			};
		}

	});

	var task1 = new Task({
		title: "my first task"
	});

### extend
KnockoutApp.Model.extend( [ protoProps, staticProps ] )

Give a Model the possibility to be extended, accepts two objects: one to extend instance properties and the second one for static properties.

	var Task = KnockoutApp.Model.Extend({
		//instance properties and methods
	},
	{
		//static properties and methods
	});

Used to extend model prototype and static methods.

### constructor / initialize
new KnockoutApp.Model( [ attributes, collection ] )

Create a new model instance, accepts two parameters:

- an object of *attributes* to be set

- if the model is inside a collection you can pass as a second parameter a reference to the collection

Instead of overriding the constructor use the *initialize* method that will be called using *apply()* from the collection so *this* will be the model.

Remember that KnockoutJS observable properties can't be defined in the model's prototype so *initialize* is the perfect place.

	Task.prototype.initialize = function(){
		//code code code
	};

### id
model.id()

An observable property, used to communicate with the server.

If its value is set to *false* model.isNew() will return true.

### attributes
model.attributes

A simple object where all the model's attributes are stored.

### defaultAttributes
model.defaultAttributes()

A function that returns an object with the default attributes of the model.

You can also define KnockoutJS observable properties.

*Must be a function since I've not implemented any clone method.*

	Task.prototype.defaultAttributes = function(){
		return {
			title: ko.observable("default title"),
			done: ko.observable(false)
		}
	}

### collection
model.collection

If the model is stored in a Collection it stores a reference to the collection.

### sync
model.sync

If this property is set, it will be used instead of KnockoutApp.Sync.

### isNew
model.isNew()

Used to detect if the model has been saved to the server.

Return *false* if model.id() is not *false*.

### fetch
model.fetch( [ options ] )

Fetch a model from the server and overrides its attributes with the one fetched.

Accepts as a parameter an *options* object tha will be passed to Knockout.Sync.

### save
model.save( [ options ] )

If model.isNew() the model will be created on the server, otherwise it will be saved.

Accepts as a parameter an *options* object that will be passed to KnockoutApp.Sync.

### destroy
model.destroy( [ options ] )

If the model is inside a collection, remove it from the collection.

If the model has been saved to the server, delete it on the server.

Accepts as a parameter an *options* object tha will be passed to Knockout.Sync.

### url
model.url()

If the model is inside a collection return the collection url plus the id property if the item has been saved to the server.

### modelName
model.modelName

If you set this property, when using KnockoutApp.Sync then the data sent to the server will be wrapped in an object, which name is modelName ( this is useful when using Ruby on Rails that wants to receive update/create parameters wrapped in an object which name is the same of the model )

	modelName: {
		//model properties
	}

### validate
model.validate()

Not implementd, returns true.

{'fraction_non_alphanumeric': 0.08253553814911517, 'fraction_numerical': 0.0002901073397156948, 'mean_word_length': 4.025510204081633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2307479', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1819, 'n_words': 928}