Skip to content

Instantly share code, notes, and snippets.

@arthuryeti
Last active August 29, 2015 14:07
Show Gist options
  • Save arthuryeti/b63c3caf7d7b760ef642 to your computer and use it in GitHub Desktop.
Save arthuryeti/b63c3caf7d7b760ef642 to your computer and use it in GitHub Desktop.
moduleKeywords = ['extended', 'included']
class NvModel
@_resource = {}
@_all = []
@all: ->
models = _.map @_all, (model) =>
model = new @(model)
$q.when models
@getEntityDefinition: () ->
@_resource.getEntityDefinition()
###*
* Extend the Class object
* @param {Object} obj Give an object of methods
* @return {Object} Return the current model
###
@extend: (obj) ->
for key, value of obj when key not in moduleKeywords
@[key] = value
obj.extended?.apply(@)
this
###*
* Extend the Instance object
* @param {Object} obj Give an object of methods
* @return {Object} Return the current model
###
@include: (obj) ->
for key, value of obj when key not in moduleKeywords
# Assign properties to the prototype
@::[key] = value
obj.included?.apply(@)
this
constructor: (entity) ->
angular.extend @, entity
@_resource.getEntityDefinition()
_.defaults @, @_resource.properties
sendToServer: ->
@_resource.entity = _.omit @, '_resource'
@_resource.create()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment