Class: restmod

restmod

new restmod()

The restmod service provides factory methods for the different restmod consumables.

Source:
  • module.js, line 53

Methods

mixin(_mix) → {object}

The mixin factory is used to pack model behaviors without the overload of generating a new model. The mixin can then be passed as argument to a call to restmod#model#model to extend the model capabilities.

A mixin can also be passed to the restmodProvider#rebase method to provide a base behavior for all generated models.

Parameters:
Name Type Description
_mix mixed

One or more mixins, description objects or description blocks.

Source:
  • module.js, line 151
Returns:

The mixin

Type
object

model(_url, _mix) → {StaticApi}

The model factory is used to generate new restmod model types. It's recommended to put models inside factories, this is usefull later when defining relations and inheritance, since the angular $injector is used by these features. It's also the angular way of doing things.

A simple model can be built like this:

angular.module('bike-app').factory('Bike', function(restmod) {
  return restmod.model('/bikes');
});

The _url parameter is the resource url the generated model will be bound to, if null is given then the model is nested and can only be used in another model context.

The model also accepts one or more definition providers as one or more arguments after the _url parameter, posible definition providers are:

  • A definition object (more on this at the BuilderApi):
restmod.model('/bikes', {
  viewed: { init: false },
  parts: { hasMany: 'Part' },
  '~afterCreate': function() {
    alert('Bike created!!');
  }
});
  • A definition function (more on this at the BuilderApi):
restmod.model('/bikes', function() {
  this.attrDefault('viewed', false);
  this.attrMask('id', 'CU');
});
  • A mixin (generated using the mixin method) or model factory name:
restmod.model('/bikes', 'BaseModel', 'PagedModel');
  • A mixin (generated using the mixin method) or model object:
restmod.model('/bikes', BaseModel, PagedModel);
Parameters:
Name Type Description
_url string

Resource url.

_mix mixed

One or more mixins, description objects or description blocks.

Source:
  • module.js, line 125
Returns:

The new model.

Type
StaticApi

singleton(_url, _mix) → {RecordApi}

Shorcut method used to create singleton resources.

Same as calling restmod.model(null).$single(_url)

Check the StaticApi#$single documentation for more information.

Parameters:
Name Type Description
_url string

Resource url,

_mix mixed

Mixin chain.

Source:
  • module.js, line 170
Returns:

New resource instance.

Type
RecordApi