Created
June 16, 2011 20:23
-
-
Save clyfe/1030168 to your computer and use it in GitHub Desktop.
CoffeeScript on a Pony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base | |
@include: (module) -> | |
@::[k] = v for k, v of module:: | |
@has_many: (rel, opts) -> | |
@::[rel] = -> console.log rel | |
@tableName: -> | |
@_tableName ?= @toString().match(/function ([^\(]+)/)[1] | |
@find: (id) -> | |
console.log "SELECT * FROM #{@tableName()} WHERE id = #{id}" | |
save: (opts = null) -> | |
tableName = @constructor.tableName() | |
if @id? | |
console.log "UPDATE #{tableName} SET k='v' WHERE id = #{id}" | |
else | |
console.log "INSERT INTO #{tableName} VALUES ('v')" | |
class Trashable | |
trash: -> @trashed = true | |
class User extends Base | |
@include Trashable | |
@has_many "roles" | |
user = new User() | |
user.trash() | |
console.log user.trashed # true | |
user.roles() # roles | |
User.find(1) # SELECT * FROM User WHERE id = 1 | |
user.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment