Class: Plaster

Plaster

Main Plaster class. Use this class to set default options and create schemas and models.

new Plaster(options)

By default we export an instance of Plaster object.
Clients can create a new instances using the constructor.

Name Type Description
options Object

default schema options

Name Type Description
strict Boolean

By default (true), allow only values in the schema to be set.
When this is false, setting new fields will dynamically add the field
to the schema as type "any".

dotNotation Boolean

Allow fields to be set via dotNotation. Default: true.
obj['user.name'] = 'Joe'; -> obj: { user: 'Joe' }

Example

var plaster = require('plaster');

var schema = plaster.schema({ name: String });
var Cat = plaster.model('Cat', schema);
var kitty = new Cat({ name: 'Zildjian' });

Members

Expose the Model class

Example

var schema = plaster.schema({ name: String });
var Cat = plaster.model('Cat', schema);
var kitty = new Cat({ name: 'Zildjian' });
console.log(kitty insanceof plaster.Model); // true

Expose the ModelArray class

Expose Plaster constructor so clients can create new instances.

Expose the Schema class

Example

var schema = new plaster.Schema({ name: String});

Methods

get(){*}

Get option.

Returns:
Type Description
* Option value

getModel(name){*}

Returns the model given the name.

Name Type Description
name
Returns:
Type Description
*

model(name, schema, options)

Creates a model from a schema.

Name Type Description
name String

name of the model.

schema Schema

instance

options Object

options

Name Type Description
freeze Boolean

to freeze model. See Object.freeze. Default: true

modelNames(){Array}

Returns an array of model names created on this instance of Plaster.

Returns:
Type Description
Array Array of model names registered.

schema(descriptor, options){Object}

Creates a schema. Prefer to use this over Schema constructor as this will pass along Plaster config settings.

Name Type Description
descriptor Object

the schema descriptor

options Object

Schema options

Returns:
Type Description
Object created Schema instance

set(key, value)

Sets Plaster config options

Name Type Description
key String

the option key

value *

option value