Plugin for helping writing ActiveRecord style/pattern code for Derby
After adding the plugin:
derby.use require 'derby-ar'
One can add model layer code automatically to the model layer:
{ChildModel} = derby.Model
class CollectionConstructor extends ChildModel
doSomethingWithCollection: ->
class ItemConstructor extends ChildModel
doSomethingWithItem: ->
class Base extends ChildModel
method2: ->
'method2'
class SubDocFirstConstructor extends Base
method1: ->
'first'
class SubDocSecondConstructor extends Base
method1: ->
'second'
class SubdocFactory
factory: true
constructor: (model, self) ->
return switch model.get('type')
when 'first'
new SubDocFirstConstructor(self)
when 'second'
new SubDocSecondConstructor(self)
derby.model('items', "items", CollectionConstructor);
derby.model('item', "items.*", ItemConstructor);
derby.model 'subdoc', 'items.*.subdoc.*', SubdocFactory
...
myCollection = model.at('myCollection')
myCollection.subscribe ->
myCollection.doSomethingWithCollection()
myItem = myCollection.at('<id of myItem>')
myItem.doSomethingWithItem()
...