Skip to content

Instantly share code, notes, and snippets.

@525c1e21-bd67-4735-ac99-b4b0e5262290
Created September 12, 2012 07:14
Show Gist options
  • Save 525c1e21-bd67-4735-ac99-b4b0e5262290/3704888 to your computer and use it in GitHub Desktop.
Save 525c1e21-bd67-4735-ac99-b4b0e5262290/3704888 to your computer and use it in GitHub Desktop.
{EventEmitter} = require 'events'
uuid = require 'node-uuid'
module.exports = class Model extends EventEmitter
constructor: ->
super
@property: (key, descriptor = {}) ->
@properties ?= {}
@properties[key] = descriptor
assert = require 'assert'
Model = require '../lib/model'
model = new Model
assert.ok model
console.log 'defining foo'
class Foo extends Model
@property 'id', type: String
console.log 'defining bar'
class Bar extends Foo
@property 'anumber', type: Number
@property 'aregexp', type: RegExp
console.log '\n'
console.log 'making foo'
foo = new Foo
console.log 'making bar'
bar = new Bar
console.log '\n'
console.log foo.constructor.name
console.log foo.constructor # .properties
console.log bar.constructor.name
console.log bar.constructor # .properties
ava:feisty pyro$ coffee test/model.coffee
defining foo
defining bar
making foo
making bar
Foo
{ [Function: Foo]
__super__: { constructor: { [Function: Model] __super__: [Object], property: [Function] } },
property: [Function],
properties:
{ id: { type: [Function: String] },
anumber: { type: [Function: Number] },
aregexp: { type: [Object] } } }
Bar
{ [Function: Bar]
__super__:
{ constructor:
{ [Function: Foo]
__super__: [Object],
property: [Function],
properties: [Object] } },
property: [Function],
properties:
{ id: { type: [Function: String] },
anumber: { type: [Function: Number] },
aregexp: { type: [Object] } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment